in reply to Re: Better way to add text to PDFs?
in thread Better way to add text to PDFs?

I found that tutorial after some googling also. I tried picking apart the pieces and came up with the following:

my $pdf = PDF::API2->open($file); my $pdpage = $pdf->openpage(1); my $text = $pdpage->text; $text->font( $pdf->corefont('Times', -encoding => 'latin1'), 12 ); $text->fillcolor('red'); $text->text("Wahoo!"); $pdf->saveas("/tmp/foo123.pdf"); $pdf->end;

Again, the result is dissapointing. The output PDF appears totally unchanged from the original. :(

Replies are listed 'Best First'.
Re^3: Better way to add text to PDFs?
by BigLug (Chaplain) on Jul 14, 2005 at 23:16 UTC
    Your code works for me .. remember from my tutorial that the origin is the lower left, so look there for your text.

    If you want it anywhere else, then $text->translate($x,$y) before you set your text (in your code, after the fillcolor.

    If that doesn't work for some strange reason, then let me know what version of PDF::API2 you're using, and any other relevant information.

    Cheers!
    Rick Measham

      Thanks for taking a look, BigLug. I'm afraid the results are the same, even if I use translate to move the text about. Note that there's no problem creating new PDFs, e.g. if I use PDF::API2->new instead of open, and page instead of openpage. If I do that, I get a nice big "Wahoo!" exactly where I expect it, so I know it's not a problem with fonts, or the geometry. But I've had no luck whatsoever in modifying existing PDFs.

      FWIW, $PDF::API2::VERSION is 1.081.