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

Posted on 2012-09-21
Last Modified: 2014-08-08
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.

Question by:apjraven
    LVL 3

    Expert Comment

    Click on FILE > PRINT PREVIEW.  At the bottom, it will show how many pages.
    LVL 16

    Accepted Solution

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    This article will show, step by step, how to integrate R code into a R Sweave document
    Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now