[Chicago-talk] Editing, altering, manipulating PDFs
eli at mortgagefolder.com
Tue Mar 27 18:34:05 PDT 2007
Yeah, the docs are pretty bad. Also, I should have sent you to PDF::API2,
not Lite. Near as I can tell, Lite is just for creating PDF from scratch,
not modifying existing ones.
The real meat of the docs for PDF::API2 is in PDF::API2::Content and
Here's a bump, to get you past the grueling docs:
# open a pdf
my $pdf = PDF::API2->open('/path/to/pdf');
# get the first page
my $page = $pdf->openpage('1');
# get the gfx object
my $gfx = $page->gfx;
# setup the image
my $image_file = $pdf->image_jpeg('/path/to/image');
# plot the image at 50,700
$gfx->image($image_file, 50, 700);
# set the font to use
my $font = $pdf->corefont('Helvetica');
# plot some text at (275,125), 25 pixels high
$gfx->textlabel(275,125,$font, 25, 'Text goes here');
# convert pdf to a string; this keeps your original pdf intact if you
# need to use it again with different data
my $new_pdf = $pdf->stringify;
# close the pdf
At this point you can open a filehandle and save the new pdf ($new_pdf)
wherever you want.
The x,y coords for plotting start at the bottom left corner.
There are methods to save your modifications back to the original pdf, but
I haven't used these.
>> You can open a pdf, add text to it, add images to it, and save the
>> resulting pdf.
>> Elias Lutfallah
>> Chief Technology Officer
>> Mortgage Desk, Inc.
> Thanks Eli, I looked at the module and I can't make heads or tails of
> it. There is almost no documentation outside of the method names.
> Could you give me an example of how to add an image to an existing PDF?
> Chicago-talk mailing list
> Chicago-talk at pm.org
Chief Technology Officer
Mortgage Desk, Inc.
More information about the Chicago-talk