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

I have been using the PDF::Labels module to create mailing labels using data from my address book. Everything works fine except one thing. I have one or two entries in my address book that contain strings that are longer than the width of the label. Shrinking the font size doesn't help. I'm wondering if anyone who uses this module has had this problem as well. If so, what did you do to resolve it?
I just want to wrap the text to the next line. Thanks in advance.
Joseph Wagner Network Manager

Replies are listed 'Best First'.
Re: PDF::Labels and word wrapping
by fglock (Vicar) on Dec 09, 2004 at 02:33 UTC

    How about pre-processing the text with one of the Text::Wrap'per modules?

Re: PDF::Labels and word wrapping
by dragonchild (Archbishop) on Dec 09, 2004 at 14:13 UTC
    *does a little sourcediving*

    I found a comment Should add code here to check width of test ... I'm assuming the author meant "text". Then again, using PDF::Create isn't the best rendering engine.

    As I see it, you've got a few options:

    • Convert to using PDF::Template. If you choose this, let me know and I'll create some templates to ease your conversion process. The benefit here is that P::T will do text wrapping for you.
    • Create wider labels. When you call PDF::Labels->new(), you pass in a pageformat option. Choose one with a wider text area. $PDF::Labels::PageFormats[1] looks to be the widest one (if I'm reading the parameters correctly).
    • Accept the fact your labels are truncated. This is the simplest, if least satisfying, option.

    I would strongly recommend not attempting to fix the code. Text-width calculations are very difficult. PDF::Template doesn't attempt to do it, instead choosing to delegate to PDFlib. PDF::Create, the rendering engine for PDF::Labels, has a very limited facility for this, which PDF::Labels doesn't even seem to be using.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.