How to find how many pages a printed web page will be?

When I Print / Print Preview a web page, the browser has the ability to put page x of y on the printed document.  Is there a way to query the browser to find out how many pages a printed page would be if it was printed?

I have a displayed web page that when it prints, normally prints to one page.  However, depending on the amount of information entered by the user, it could print to 2 or more pages.  In that case I want to add conditional page breaks (using page-break-before) to break up the information in the desired format.

Thanks!
apjravenAsked:
Who is Participating?
 
grahamnonweilerCommented:
The "page-break-after: always" CSS will need to be inserted either in to <div> or <table> (the latter being a safer option for printed output.

Server-side is simpler than client-side.

I am assuming you do not have accesss to server-side scripting, as you have only stated HTML/JavaScript. Thus you need to have an "onload" event trigger a Javascript function.

This function needs to count the number of <divs> / <tables> and then add the CSS attribute to the relevant <div> / <table> to handle the page breaks. After it has added the page-breaks the function can trigger the window.print()

If you post your HTML source here then a sample script could be provided.

Conversely, if you have access to server-side scripting, then the prinicple is the same, except that the CSS page-break can be inserted while building the content.
0
 
doublestickCommented:
Click on FILE > PRINT PREVIEW.  At the bottom, it will show how many pages.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.