Many web sites use Perl for creating dynamic content.
You can also use Perl to script Acrobat on your local machine . Given the great number of
packages that extend Perl, it is no surprise that packages exist for
creating and manipulating PDF. Let's take a look.
Install Perl and the PDF::API2 Package on Windows
explains how to install
Perl on Windows. After installing
Perl,
use the Perl Package Manager to easily install the
PDF::API2 package.
Launch the Programmer's Package Manager (PPM,
formerly called Perl Package Manager) by selecting Start →
Programs → ActiveState ActivePerl 5.8 → Perl
Package Manager. A command prompt will open with its
ppm> prompt awaiting your command. Type
help to see a list of commands. Type
search pdf to see a list of available packages. To
install PDF::API2, enter installpdf-api2. The Package Manager will fetch the
package from the Internet and install it on your machine. The entire
session looks something like this:
PPM - Programmer's Package Manager version 3.1.
Copyright (c) 2001 ActiveState SRL. All Rights Reserved.
Entering interactive shell. Using Term::ReadLine::Stub as readline library.
Type 'help' to get started.
ppm> install pdf-api2
====================
Install 'pdf-api2' version 0.3r77 in ActivePerl 5.8.3.809.
====================
Transferring data: 74162/1028845 bytes.
...
Installing C:\Perl\site\lib\PDF\API2\CoreFont\verdanaitalic.pm
Installing C:\Perl\site\lib\PDF\API2\CoreFont\webdings.pm
Installing C:\Perl\site\lib\PDF\API2\CoreFont\wingdings.pm
Installing C:\Perl\site\lib\PDF\API2\CoreFont\zapfdingbats.pm
Installing C:\Perl\site\lib\PDF\API2\Chart\Pie.pm
Successfully installed pdf-api2 version 0.3r77 in ActivePerl 5.8.3.809.
ppm> quit
The PDF::API2 package is used widely to create and manipulate PDF.
You can download documentation and examples from http://pdfapi2.sourceforge.net/dl/.
Hello World in Perl
This Perl script creates a PDF named
HelloWorld.pdf,
adds a page, and then adds text to that page. It gives you an idea of
how easily you can create PDF. shows the
PDF document created by this script.
Figure 1. Creating PDF content using Perl
#!/usr/bin/perl
# HelloWorld.pl; adapted from 0x_test-pl
use PDF::API2;
my $pdf = PDF::API2->new(-file => "HelloWorld.pdf");
$pdf->mediabox(595,842);
my $page = $pdf->page;
my $fnt = $pdf->corefont('Arial',-encoding => 'latin1');
my $txt = $page->hybrid;
$txt->textstart;
$txt->font($fnt, 20);
$txt->translate(100,800);
$txt->text("Hello World! left-aligned");
$txt->translate(500,750);
$txt->text_right("Hello World! right-aligned");
$txt->translate(300,700);
$txt->text_center("Hello World! center-aligned");
$txt->textend;
$pdf->save;
$pdf->end( );
Discover Perl Packages with CPAN
CPAN (http://www.cpan.org) is the Comprehensive
Perl Archive Network, where you will find "All
Things Perl." Visit http://search.cpan.org to discover several
other PDF packages. Drill down to find details, documentation, and
downloads. For example,
PDF::Extract
(http://search.cpan.org/~nsharrock/) creates a
new PDF from the pages of a larger, input PDF.
I've just bought the "PDF Hacks" and followed the instructions in Hack #86 and have got the following message:
Can't locate object method "hybrid" via package "PDF::API2::Page"....
I bought the book just for this hack, so can anyone point me in the right direction?
I presume the ppm installer hasn't don'e its job properly, but I don't want to start playing with the modules!
Thanks