dynamic content with PDF::API2

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I've been using PDF::API2 for years without a problem of any kind, but now have
a new requirement -- text wrapping. Here's an example:

#from a hashref from a database, name could be NULL
my $name = $hashref->;
my $sentence = '';
$sentence = "Hello, my name is $name." if $name;

#in PDF code
$text->text("Greetings. $sentence Here is some information.");

This works if $name is NULL, because $sentence takes up no space and the end
result contains two spaces after the greeting, which isn't a big deal.

However, there's a big difference between 'Ed' and 'Barack Hussein Obama.' The
longer names cause the line to run off the right margin.

Is it possible to wrap text in PDF::API2? I've looked and can't see how.

I could write my own wrapping routine, but would rather not.

I also don't want to use another module (maybe CAM::PDF) but would rather not,
and I haven't looked at the other modules to see if they can wrap text.

Thanks, CC.

Re: dynamic content with PDF::API2

Quoted text here. Click to load it

PDF::API2::Simple has a simple-minded text-wrapping feature, or you
could use Text::Flow::Wrap to wrap the text before writing it to the

Doing text wrapping properly is Hard. If you care about the quality of
your output you ought to be using a proper typesetting program like TeX.
(Modern versions of TeX, LuaTeX and ConTeXt in particular, are much less
gnarly than they used to be, especially when it comes to using ordinary
fonts.) You could also consider generating something you can feed
through InDesign or <spit> Word.


Re: dynamic content with PDF::API2

On Sunday, August 12, 2012 2:02:04 PM UTC-4, Ben Morrow wrote:
Quoted text here. Click to load it

Thanks, Ben. Yes, wrapping is hard. All I've ever done is placing fixed sized
objects on a PDF, and since the main requirement has been uniform appearance of
the PDF, PDF::API2 has worked out real well for me.

I am very fond of LaTeX and am known locally as an evangelist of LaTeX, but I
like things real simple, and using the suggested alternatives (not by you) such
as printing to RTF or DOCX and so on cost much more than the benefit.

As much as I hate to, I'm going to tell my user that he has to modify his layout
to accommodate my inability to wrap his text. Fortunately and unusually, he is
tech savvy and understands why, so it won't be a problem.

Thank God for understanding users, CC.

Site Timeline