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:
- call the 'new' method.
- create an image object.
- define page height and width for the image object.
- define the image coordinates for the image object.
- 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:
- PDF Concatenation and Extraction Tool.
- http://www.as220.org/shawn/PGP/examples/example12-4.txt.
- http://rick.measham.id.au/pdf-api2/.
Excellence is an Endeavor of Persistence.
Chance Favors a Prepared Mind.
| [reply] [d/l] [select] |
| [reply] |
I feel your pain -- getting started with PDF modules in Perl is an uphill battle. I don't know if this will help, but here's a little snippet (posted in the dimly-lit "Snippets" wing of the Monastery): One PDF file for a set of images.
You might also try putting "PDF::Create" or "PDF::API2" into Super Search, to find whatever nodes (in whatever sections) might contain other code examples using these modules. | [reply] |
Thanks - unfortunately this is for an image.
What I can't figure out is why all the examples deal with single lines or images and neglect to deal with what is surely the most common case? - a text based document. I'd just like to be able to write out lines to a PDF rather than a file...
Will also try your supersearch suggestions. Meantime if anyone has any code they'd be willing to share for printing out a few lines to a PDF file that would be awesome!
| [reply] |