Hi All:

I am working on generating pdf documents using API2. The format is tight and I have a small amount of real estate in which to display freeform text, which HAS to be in a variable pitch font. The only way to handle this situation is to dynamically change the text size output to the pdf document.

To date I have implemented a scheme to look at the block of text to determine the total number of characters, total number of words, characters per word, etc.. I then step through a matrix I setup to guess based on a certain font size the number of characters and/or words that will fit on a single line, and how many lines will fit into the given area, based on number of words, characters per word, number of resulting lines, etc.. I then dynamically adjust the font size and the number of words per line until I find a combination that will allow me to display the text in the allotted area.

Unfortunately, since it is a variable pitch font if try to use as much of the page as possible and I run into instances where if the text has a lot of "fat" characters the text is truncated off of the page. If I set my matrix up in conservative mode and the text has a lot of skinny characters then I am left with a lot of unused whitespace. I am continually tweaking this algorithm, making it better in some cases and worse in others!

Every time I revisit this code I keep thinking that there must be a better way. My problem is that I am basing my font size decisions based on the number of characters/words, where is really has to be based on the size of the character as rendered by API2. Is anyone aware of a way in API2 that I could to something like setup a text area and then let API2 determine the best way to present the data?

Thanks!

In reply to Adjustable pdf text size in API2 by fss0099

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.