Html – force an HTML document to be one page long

documenthtmlprinting

I am generating a document from HTML. Is there any way to force the HTML page to be one rendered as one printed page long?

I've done most of the page with <table> and <div> tags.

Best Solution

Not exactly, but you can use a print-stylesheet:

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

To set font sizes, paddings, etc. to physical units like 'pt' (that should never be used in a screen-stylesheet!) so that it ends up being more or less an A4 page, when rendered in a typical browser, with typical fonts, with a following wind. Nothing is guaranteed but you can optimise for the common case.

In print you don't have to worry so much about font size preferences or dpi settings, but you still can't control the margins the browser uses or the actual page size (US Letter is smaller than A4), so leave a good amount of wiggle room and test on the major browsers.