Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to print a web page using JavaScript...

Status
Not open for further replies.

kishorkar

Programmer
Aug 12, 2003
26
IN
Hi all,

I have a excel document exported to a web page. The excel sheet has lot of columns. The excel sheet is exported to a web page and i want my javascript code to check whether the data can fit in potrait format (A4 size sheet), if not it should change the settings to Landscape format. How will i do this?

Let me know ASAP.

Thanks and Regards,
Kishore
 
You will not be able to do this cross-browser.

It might be possible in IE-only using some ActiveX control, etc... but the reality is, you just cannot get good print control using JS.

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
You have no way of accurately predicting how the font will render on the client's machine and that will affect the width, height, and spacing of the text. Furthermore you cannot tell with any certainty what the margin/border settings for the printer may be. Different printers have different minimum margins and some can print edge to edge.

Dan, how about something like this though.
What if a new div or window is created to render the document into and set to allow the overflow, then read back in the number of pixels wide/high the new window is as an estimate of how it might fit on the printed page assuming a minimum .25" border on all sides? The pixels can calculate into inches easily enough though we would have to make assumptions as to the media size it will print to in order to determine if it will fit landscape or portrait.

I have not thought much on the subject and it's still early so my brain is still a bit foggy and I may be missing out on some obvious roadblock to the idea.

If this works it could also be an approach to adjust web pages with automatic page breaks in the correct places for the printed content so you could have a breaking-row option when printing table data multi-page.

Might be a project worth playing with.



Stamp out, eliminate and abolish redundancy!
 
As far as I know the DPI setting will not alter the size of the print, only the density of the printing so to create a higher quality character. An inch of print at 72dpi is the same as an inch of print at 600dpi on a printed page, one is just filled with smaller dots to fill it out better and make it a higher quality image.

The biggest problems I see are knowing what the material in the output tray is for size and what minimum page margins are for that printer but I would think it safe to assume any printer in the last 5 years or so would not force greater than a .25" margin. I think the HP LJ8500 I print to has a .20" left/right margin minimum.


Stamp out, eliminate and abolish redundancy!
 
Yes - but a 300x300 pixel, 72 DPI image printed at 300 DPI will be bigger than if the same image is printed at 600 DPI.

Only if the printer is left to define the size of the image on the page. If you were printing a web page with a high DPI image but had set a fixed size for it in your HTML it should still print only at the size defined. It's only when we let the printer or printer driver define the dimensions that it get's larger. If they do not specify dimensions on their image tags then they are not adhering to standards and cannot expect accurate output. :)

I could be wrong about the image but I do not think so. Might play around with it later but I do not think I am going to have time today.


Stamp out, eliminate and abolish redundancy!
 
Dan said:
Yes - but a 300x300 pixel, 72 DPI image printed at 300 DPI will be bigger than if the same image is printed at 600 DPI.
Sorry Dan, but I have to differ with you on this one...

A 300x300px, 72 DPI image, when printed on an (extremely) old 7-pin, 25 dpi dot-matrix printer will come out 4.17" wide, and 4.17" tall (though now it would only be 25 dpi). The same image, printed on an HP PhotoSmart 7250 @ 4800x1200 max. DPI will still be 4.17"x4.17" on the printed page; it'll just have a LOT of TINY dots crammed into each of those original 72x72dpi dots.

End result:
I think thenightouwl is onto something that could prove useful here. I, however, have neither the time nor the energy to follow his thinking to it's logical conclusion...my brain's already hurting. LOL




I hope this helps;
Rob Hercules
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top