tags:

views:

46

answers:

2

Hi,

I have a report I need to print out in an application I'm usually doing maintenance for. My question, which interests me beyond the scope of this task is, what are the ways to format an HTML page for printing? What are the pros and cons of each?
Note that the page is meant only to be printed. I'm not asking about an HTML page that looks ok also when printed.

Generally speaking, I know I can either rely heavily on <table>s or on <div>s, but I don't know which way to go.

I would also appreciate some resources to get me started, or to help with known problems, in any method you suggest.

Thanks, Asaf

+1  A: 

As you can certainly see, printing and web presentation are two different creatures. The main issue is the bounds of the printed page, which does not exist in a web page. Even if you think you have a page laid out in a manner that will fit a printed page, then you need to deal with the fact that the font you are using may not work or scale correctly on the user's printer.

I know of three ways to deal with this issue:

  1. Use fixed-sized fonts (like Courier), limit yourself to an 80 column width, and only use font characters: meaning use something like asterisks for borders, etc. This is VERY old school - your reports look simple and old and plain. But, they will always print they way you intended.

  2. Convert your report to an image. Images can be made to confirm to a specific size which can fit on a page. However, you can still have issues due to printer margin settings.

  3. Let another application do the work for you. What I mean by this is put your report into a PDF or a spreadsheet. Both PHP and Perl have easy to use modules for creating a PDF - with no licensing needed. Perl has a fantastic spreadsheet module. This route takes a little learning up front, but frees you from having to be an expert on printing (which can be a real pain).

menkes
Thanks - these are good tips, but the company I'm doing this for already works with some HTML reports (I peaked at their code, it's table based and really ugly). They're used to the limitations of HTML, so I'd like to focus on the best way to do it.
Asaf R
A: 

In case you DO want to have a page that also looks good when viewed in a browser, consider multiple stylesheets for different medias.

Zeta Two