So you want to create PDF files.

If you're starting out with PostScript fonts, a good idea when attempting to generate PDF; and you have the associated .afm files (more like a rarity these days), then one option is to use the old module Font::AFM, and its method stringwidth(), to calculate the physical width of a piece of text, in the font size you like.

Another option, at least when you're using one of the standard PDF fonts, is to use the PDF::API2::CoreFont module. As the docs say:

$wd = $font->width($text) Returns the width of $text as if it were at size 1.
In order to get the size at other font sizes, just multiply by the font size.

In reply to Re: Font size by pixels. by bart
in thread Font size by pixels. by the_0ne

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.