dynamic content with PDF::API2



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->{$key}{name};
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.


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.

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.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Latest member

Latest Threads