Script for Printing

Question: I am looking for a script that will automatically resize a webpage to fit a standard sheet of paper without haveing to hit fit to page or any other command. I am not sure if the script I am looking for is Javascript.

Answer: If you design your web pages properly so that they will fit the browser window regardless of how your visitors have it set then the same page will resize itself appropriately for printing.

If you are using a fixed width layout then stay below 720px width as any wider than that may not fit on the page. The exact amount that will fit across the page depends on the printer, the margin settings in the operating system, and whether standard A4 paper or US letter sized paper (which is slightly wider but a lot shorter) is being used.

If you want more control over print layouts then set up a separate stylesheet with media="print".

The only Javascript command that relates to printing is document.print() which will open the print dialog box to allow the person to print the current page.

JScript (the Internet Explorer equivalent to Javascript) has tw event handlers that relate to printing onbeforeprint and onafterprint. If you are using IE6 specific hacks to substitute for the min-width and max-width stylesheet properties available to more modern browsers then you may need to use those event handlers for that browser only to fix the width for printing.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow