artist has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I have a simple request to find the number of pages it will require to print an HTML page.

I explored the print option of Internet Explorer a little bit and I can do page setup with variety of option including paper size, margin, header, footer etc..
Also explored the 'print' modules from CPAN such as printer and Net::Printer but not helpful in this case.

I have to find the number of pages it will take to print in 'proportional font' such as ariel where width of 'i' is not same as 'w'. Also have to find out for different font size, left margin, different paper sizes etc..

Notice that Internet Explorer (version 6.0) has 'print preview' function which also tells you how many pages in total it will take.
Aware of that 'number of pages' "may" change with printer model and print driver.
Please suggest appropriates.

Thanks,
Aritst.

Replies are listed 'Best First'.
Re: Number of Print Pages
by traveler (Parson) on Apr 30, 2002 at 22:15 UTC
    To do this you have to know font metrics, page sizes and have the ability to render (or virtually render) the HTML. I don't know of a pure perl way to do this. The browser is at an advantage here as it has already done the rendering. There is, however, htmldoc that can render web pages to Postscript or PDF. It is not free. You could use that and then get a page count.

    If your program uses Gtk, I think it can render HTML with Gtk::HTML::Simple. You might then be able to gather the information from that (perhaps by converting it to Postscript). I've never tried this.

    HTH, --traveler

Re: Number of Print Pages
by Spudnuts (Pilgrim) on May 01, 2002 at 18:20 UTC
    That's not a simple request because the user can override (through accessibility options) any font settings on which you would base your notion of page count. The printed content is based on how the user displays it--not necessarily on how you present it. If you want to be able to gauge page counts, you will have more luck generating a .DVI file, a .PDF, or a .RTF, as these are not as closely tied to the user's environment.
Re: Number of Print Pages
by artist (Parson) on Apr 30, 2002 at 22:36 UTC
    Hi
    I also noticed that when I choose 'print to file' option it prints to a *.prn file which has 'number of pages' at the bottom of the file.

    How I can simulate in command line ?

    thanks,
    Artist

      I am unaware of a way this can be done easily in Perl. Maybe there is something available in Javascript, or a Microsoft scripting language, however. Have you tried looking at the Microsoft Developer Network for more information on this?

      If that fails, then maybe you should snoop around or post a message to the newsgroup microsoft.public.internetexplorer.scripting. Good luck!

      - wil

      Not certain how to do this, but may be able to give you a few hints. Internet Explorer has, I believe, got an OLE interface which can be linked with any scripting language- including Perl. Assuming this OLE interface allows you to do the 'Print to file' command scripted then you should be able to grab the output and throw a basic regexp at it to pull out the page count.

      I have had a quick look at the MS website, but couldn't find the documentation on IE's OLE interface. I suspect you should be able to find it at a website dedicated to a Win32 specific-language such as Visual Basic or somesuch though.