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

Hi Monks
In the attempt to find out how many pages it will take to print an HTML page, I want to count it myself rather than Internet Explorer. I want to find out what would be the letter size in tirms of pixel width it will take for proportional fonts like Ariel.

My dear monks, please suggest me some good pointers. What I am looking for is from experienced people, who know which modules from CPAN to use etc..

Thanks,
Aritst

Replies are listed 'Best First'.
Re: Letters Width
by dws (Chancellor) on May 06, 2002 at 21:45 UTC
    I want to find out what would be the letter size in tirms of pixel width it will take for proportional fonts like Ariel.

    You've bitten off a difficult problem. Assuming that the user hasn't overridden your style sheet, it's going to be nearly impossible to calculate absolutely correct numbers, but with a bit of manual work, you can get an approximation.

    Start with some text of known width, and measure. 12345678901234567890123456789012345678901234567890 aaaaaaaaaaaaaaaaaaaa
    ...
    iiiiiiiiiiiiiiiiiiii
    ...
    MMMMMMMMMMMMMMMMMMMM

    Then do a little measuring and division, and you can come up with a table of character width estimates.

Re: Letters Width
by FoxtrotUniform (Prior) on May 06, 2002 at 21:43 UTC

    This is platform-dependant.

    I know that the Win32 GDI API has functions describing font metrics and character sizes, so you might find Win32::API useful.

    Sorry I can't provide more useful information; my Win32 reference is at home, buried under mountains of paper (and I hope it stays that way :-), and I'm unfamiliar with font rendering in Perl in general.

    --
    :wq

Re: Letters Width
by tadman (Prior) on May 07, 2002 at 06:41 UTC
    The short answer is "mu".

    The long answer is that you can really only guesstimate how many pages it will take. There are many variables which will impact on how much paper will be consumed:
    • Paper size (8.5"x11" vs A4)
    • Font used, and size thereof ("Arial" vs. "Helvetica")
    • Margin settings
    • Optional headers and footers
    • Browser being used
    • Operating system and settings, such as anti-aliasing
    • Printer peculiarities (laser vs. inkjet)
    So if you can figure out an average, you get an idea. Otherwise, you might want to just suggest using the "Print Preview" function, which is always accurate.

    Even if you know the width of the characters, you will have to calculate how images are inlined, words wrapped, and before you know it, you will be writing a Web browser simulator, which is probably an exercise in futility.
      Hi,
      Thanks,
      I know the IE-print, but currently I cannot take the value from 'Print Preview' as read on MSDN/Microsoft Site that they don't expose the print functionality 'currently'.
      Plus, I don't have graphics on page now, so there's no wrap arround.
      For my application Fonts are going to be ariel which are proprotional font (that's why I need char width in terms of pixels) and I will be knowing the paper size, margins, header,footer, OS, Browser ahead of the time.
      I don't know how printer peculiarities will affect, but I would know the type of current printer etc.. for this application for now.
      So it wouldn't be as high as a Web Browser Simulator.

      I know that the task is complicated and I want to have some fun too.

      Artist

Re: Letters Width
by kappa (Chaplain) on May 07, 2002 at 09:20 UTC
    This is almost as hard as to program a whole html-renderer engine. Moreover, this engine should be equivalent to Internet Explorer's one, or your page count estimate could mismatch the real one.