in reply to Perl to PDF

Maybe you wanna get familiar with PDF::API2::Lite first, I've faced a similar situation with PDF::API2 so I used PDF::API2::Lite and familiarized myself with it and when I read the PDF::API documentation it became less arcane, here are the steps for PDF::API::Lite:
  1. call the 'new' method.
  2. create an image object.
  3. define page height and width for the image object.
  4. define the image coordinates for the image object.
  5. call the 'saveas' and pass it 'filename.pdf'.
Here is my code example, for the methods 'new' and 'saveas', if you call them outside the loop, you get a multiple-page pdf file, if you call them from within the loop you got different pdf files for every image.
#!/usr/local/bin/perl use strict; use warnings; use File::Find; use PDF::API2::Lite; my $dir = "."; #my $pdf = PDF::API2::Lite->new; in case you want one pdf file find(\&find_convert, "$dir"); sub find_convert{ if(/.*\.jpg/){ my $image = $File::Find::name; print "$image\n"; convert(); } } sub convert{ #the are repeated for every match my $image=$_; my $pdf = PDF::API2::Lite->new; my $imageObject=$pdf->image_jpeg("$image"); $pdf->page($imageObject->width, $imageObject->height); $pdf->image($imageObject,0,0); $pdf->saveas("$image.pdf"); }; #$pdf->saveas("$image.pdf"); images are included in the same file...
Here are some examples using PDF::API2:
  1. PDF Concatenation and Extraction Tool.
  2. http://www.as220.org/shawn/PGP/examples/example12-4.txt.
  3. http://rick.measham.id.au/pdf-api2/.


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.

Replies are listed 'Best First'.
Re^2: Perl to PDF
by CColin (Scribe) on Nov 20, 2009 at 00:40 UTC