in reply to Better way to add text to PDFs?

BigLug wrote a tutorial for PDF::API2 at this site. I used those ideas to do just what you want.

HTH

Replies are listed 'Best First'.
Re^2: Better way to add text to PDFs?
by friedo (Prior) on Jul 14, 2005 at 20:08 UTC
    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. :(

      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.

Re^2: Better way to add text to PDFs?
by BigLug (Chaplain) on Feb 13, 2007 at 13:59 UTC