473,320 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

iframe and printing issues

Hi,

I have an excel spreadsheet that is displayed within an iframe.

I print the sheet displayed by using the function:

function printExcel(){

window.excelFrame.focus();
window.excelFrame.print();

}

This does the job BUT the sheet is printed out over 4 pages in a larger font than had I printed the page from excel itself. The original excel sheet is set up so that the contents of the sheet fit all onto one page.

Is there anything I can do to control the print area of the contents of the iframe?
Does anyone have any suggestions?

Thanks in advance.
Sep 11 '08 #1
16 8039
acoder
16,027 Expert Mod 8TB
If the Excel sheet is not contained within an iframe, does it print how you want it to?
Sep 11 '08 #2
Yes - when the excel is not in the iframe it prints just the one page. When I print it in the iframe it prints the contents of the sheet over 4 pages.
Sep 14 '08 #3
acoder
16,027 Expert Mod 8TB
What code are you using for displaying the Excel sheet? You may need to use a print stylesheet to control the printing.
Sep 14 '08 #4
I simply have an iframe called "excelFrame" and one button called Print. When the user clicks the button --> onClick="printExcel()" -->

function printExcel(){

window.excelFrame.focus();
window.excelFrame.print();

}

The excel sheet prints but it prints the sheet our over 4 pages. If I print directly from the original file using excel, the sheet prints out nicely on one page.

How can I control the printing area etc. of the iframe using stylesheets?
Sep 15 '08 #5
By the way, here is all the code - obviously fileName is the address of the excel file on the local machine:

[HTML]<% String fileName = request.getParameter("fileName"); %>

<script type='text/javascript'>

function printExcel(){
window.excelFrame.focus();
window.excelFrame.print();
}

</script>

<HTML>
<BODY>
<input type="button" id="print" onClick="printExcel()" value="Print">
<iframe id="excelFrame" src="<%=fileName%>" width="90%" height="80%"></iframe>
</BODY>
</HTML>[/HTML]
Sep 15 '08 #6
acoder
16,027 Expert Mod 8TB
See Going to Print. You can try setting the font size in the print stylesheet.
Sep 15 '08 #7
I tried this:

[HTML]<link rel="stylesheet" href="print.css" type="text/css" media="print" />

<div id="printDiv" name="printDiv">
<iframe class="tborder" id="excelFrame" src="<%=fileName%>" width="90%" height="80%" frameborder="0"></iframe>
</div>
[/HTML]
And then in my print.css file:

Expand|Select|Wrap|Line Numbers
  1. #printDiv {  font-size: 9pt; }
  2.  
But this does not seem to have any affect whatsoever.

I'm not even sure why logically it would make sense to set the font-size. My excel spreadsheet contains all sorts of fonts and even images. So how would font-size affect those?
If I had instead of an excel, an image loaded into the iframe would setting the font size in the iframe make a difference to the size of the image when it is printed from the iframe?
Sep 15 '08 #8
omerbutt
638 512MB
I tried this:

<link rel="stylesheet" href="print.css" type="text/css" media="print" />

<div id="printDiv" name="printDiv">
<iframe class="tborder" id="excelFrame" src="<%=fileName%>" width="90%" height="80%" frameborder="0"></iframe>
</div>

And then in my print.css file:

#printDiv { font-size: 9pt; }

But this does not seem to have any affect whatsoever.

I'm not even sure why logically it would make sense to set the font-size. My excel spreadsheet contains all sorts of fonts and even images. So how would font-size affect those?
If I had instead of an excel, an image loaded into the iframe would setting the font size in the iframe make a difference to the size of the image when it is printed from the iframe?
when working with printing the document you have to keep these two things in mind
1. the pixel should be avoided
2.points should be preffered
WHY ? because there is not any such thing like PIXELS in the world of printing / printers they take up or read every thing in points
and similarly there is nothing like POINTS in the world of computer screen they read up every thing in pixels
regards,
Omer
Sep 15 '08 #9
I'm confused - that is what I did - I set the font-size to 9 points...
Sep 15 '08 #10
When I check out Print Preview in Excel of the document, I can see that it is scaled down 54% to be printable on one page. Is their something equivalent that I can do to the document when it is loaded into the iframe?
Sep 15 '08 #11
acoder
16,027 Expert Mod 8TB
I'm not even sure why logically it would make sense to set the font-size. My excel spreadsheet contains all sorts of fonts and even images. So how would font-size affect those?
The reason why I suggested font size was that you mentioned in your original post that the font size was larger in the print out from the iframe. The reason your code had no effect was that an iframe is a separate document, so the stylesheet would have to be inside the iframe. I guess it's not as simple as I had originally thought which I had assumed based on your original post.
If I had instead of an excel, an image loaded into the iframe would setting the font size in the iframe make a difference to the size of the image when it is printed from the iframe?
No, it wouldn't. Do the images come out the right size when printed over 4 pages?
Sep 15 '08 #12
acoder
16,027 Expert Mod 8TB
When I check out Print Preview in Excel of the document, I can see that it is scaled down 54% to be printable on one page. Is their something equivalent that I can do to the document when it is loaded into the iframe?
Not with JavaScript, but if your target is only one specific browser for a controlled user base, you could consider using a browser-specific solution. If not, you would have to include the stylesheet within the iframe.
Sep 15 '08 #13
I am only going to be using IE - what sort of possible browser-specific solution is there?

By the way I tried to include a stylesheet within the iframe but setting the font size didn't change the output in any way either. I thought I would have to set the dimensions if it were possible of the "content" somehow because I am assuming that the iframe treats the excel sheet like it would an image and just displays the true size of it.
Sep 15 '08 #14
acoder
16,027 Expert Mod 8TB
You can use ActiveX. There's an ActiveX control called Meadroid that you may find useful.

If you go with the HTML/CSS route, you could point the src to an HTML page which contains the Excel sheet contained within a div of the right size. I haven't tried it, so wouldn't know if it works.
Sep 15 '08 #15
I checked out the ActiveX control called Meadroid. It seems that it only works with html files that are loaded into iframes and not actual documents. When I linked to my excel sheet it did not recognise it and all it gave me to print was a blank page (even though the excel appeared in iframe in the browser).

I have now given up with the idea of displaying the excel in an iframe. Instead I have created a button that when clicked will open up a new window and display the excel there. This way when using the print option from the browser menu, the sheet prints out exactly the way it should.

For those who may be interested, this is all I placed in the jsp/html file to get the excel to load up in the window:

<%
String fileName = request.getParameter("fileName");
%>

<meta HTTP-EQUIV="Content-Type" CONTENT="application/vnd.ms-excel"; />
<meta http-equiv="refresh" content="10;URL=<%=fileName%>"> </meta>

Meanwhile, thanks to acoder who has tried to help me with my problem.

Over and out.
Sep 16 '08 #16
acoder
16,027 Expert Mod 8TB
A much simpler solution. There's probably something out there that someone knows that can get the iframe printing to work as desired, but in the meantime, I guess this will have to do. Thanks for posting.
Sep 16 '08 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Marina Ferguson | last post by:
Hi, I have a document with an iframe. The main doc has a "Print" button. The idea is that when the user clicks it, the contents of the iframe is printed. For some reason instead of the iframe...
3
by: Andres Mas Torrecillas | last post by:
Hi! I'm having a little trouble with an IFRAME added in an HTML page. IFRAME has a fixed size and it contains another HTML page, which only has some text paragraphs and a pair of images aligned...
2
by: nightstar | last post by:
I am creating a web page that will contain multiple Iframes. One of the Iframes will contain a bill of sale that is generated by a script on x.mydomain.com/somefile.php?someparameters. One of the...
1
by: Poonam | last post by:
Hi I have a page where there is table and below the table there is 'iframe', This page also has 'Print' button. Printing this page is printing the table and iframe contents on 2 different...
10
by: jon | last post by:
I'm trying to use a hidden iframe to print the contents of one div seamlessly. Currently I can create the hidden iframe, copy the contents of the div to the iframe, and print it. I even have a...
7
by: Tom Cole | last post by:
IFrames have been used by years for people to accomplish many of the tasks the XMLHttpRequest does for them now...I unfortunately am late in the game and XMLHttpRequest was already out there by the...
23
by: vunet | last post by:
It is recommended by some sources I found to create IFrames in IE using document.createElement('<iframe src="#">') instead of document.createElement('iframe'). Why and what browser versions to...
8
by: jay123 | last post by:
hello, i really need help from you experts. my problem is i have one page abc.aspx, and then their is other page called def.aspx(which is printable version), which gives some information used...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.