Trouble with PDF::API2 paragraph function

We have some ancient code for printing documents that relied on the PDF::API2 module. When we upgraded our systems, this module has some different behavior and our program was throwing errors.
First, I commented out the “pdf->page->text->compress” function calls and that helped. But some text was not showing up. Turns out the “text->paragraph” function totally changed. Thankfully google led me to this page where I found the proper way to update my paragraph calls:

OLD
$text->paragraph("Hello, just a test."x10, -x => 300, -y => 600, -h => 600, -w => 200);

NEW
$text->translate( 300, 600 );
$overflow = $text->paragraph( "Hello, just a test. "x10, 200, 600 );

Scary note at the bottom, but applying the change above worked for me!
DEVELOPER METHOD means:
1. This method may not do anything useful.
2. This method may erase your hard disk(s).
3. This method may erase the hard disks on any machine your machine is connected to.
4. This method is subjected to change *without* notice.

This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Trouble with PDF::API2 paragraph function

  1. Justin Catterall says:

    $text->paragraph() returns a list, in addition to $overflow you get the new $y (vertical position) for the next paragraph. So I use:
    my ($overflow, $new_y) = $text->paragraph($para, $page_width, $y, align => ‘left’);

    Obviously your post is no longer new, and you’re probably no longer having problems with this, but the PDF::API2 documentation leaves something to be desired, and I think this problem still catches some people, and solutions are hard to find, so I thought I’d leave a comment to try and help anyone else who finds this.

  2. Max P says:

    Since I came across this page in a web search, I thought I’d add a couple things:

    Justin’s new_y comment was very useful. Just a quick note that it should be -align rather than align.

    Also, utf8 was driving me crazy until I added “use Encode” and then changed the call to:

    my ($overflow, $y) = $text->paragraph(decode(“utf8”, $para), $width, $y, -align => ‘center’);

    Hope that’s helpful!

Leave a Reply

Your email address will not be published. Required fields are marked *