[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 321
  • Last Modified:

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!
0
apjraven
Asked:
apjraven
1 Solution
 
doublestickCommented:
Click on FILE > PRINT PREVIEW.  At the bottom, it will show how many pages.
0
 
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now