PDFLib::PPS -- PDFLib Personalization Server OO Interface
use PDFLib::PPS; my $search_path = "$FindBin::Bin/../data"; my $template = "boilerplate.pdf"; my %data = ("name" => "Victor Kraxi", "business.title" => "Chief Paper Officer", "business.address.line1" => "17, Aviation Road", "business.address.city" => "Paperfield", "business.telephone.voice" => "phone +1 234 567-89", "business.telephone.fax" => "fax +1 234 567-98", "business.email" => "victor\@kraxi.com", "business.homepage" => "www.kraxi.com" ); my $pdf = PDFLib::PPS->new(filename => "/tmp/business.pdf", SearchPath => $search_path, BlockContainer => $template, BlockData => \%data); $pdf->fill_in or die "unable to fill in the block container";
PDFLib::PPS is a convenience wrapper/OO interface around the PDFlib Personalization Service. See www.pdflib.com for info about the PPS.
The goal is to be able to associate some key/value pairs with a template (i.e., a "Block Container") and end up with a PDF.
The object creation is delegated to PDFLib; see the PDFLib perldoc for details. There are three additional parameters which might be useful: SearchPath (which is then set as the SearchPath parameter), BlockContainer (the PDF document with the named blocks defined within, maybe well thought of as a "template"), and BlockData (a hashref of block-name => block-text pairs).
NB: the block-text specified in BlockData can be text, in which case the fill_in method attempts to use a reasonable encoding, font, textsize, and so forth or it can be a hashref. If a hashref is specified, one key, "text", represents the text for the field, each of the other keys/value pairs will be passed as a key=value option to PDF_fill_textblock. If "encoding" is one of the keys, that encoding will be used instead of whichever encoding PPS.pm had magically selected. (See zapfchar() below for a brief example.)
Shoves BlockData into the BlockContainer specified. Returns undef on error or the string "OK" upon success.
All identically named blocks with the block property "PDFlib:field:type" set to "textflow" will be considered a single textflow block. This is experimental and fraught with peril.
Return the ASCII character that will produce the unicode character supplied. For instance, to fill in a checkbox block named "GenderMale" with a 16 pt checkmark:
my $checkmark = PDFLib::PPS->zapfchar('CheckMark'); $pdf->block_datum(GenderMale => { text => $checkmark, fontsize => 16 });
Get/Set the SearchPath parameter.
Get/Set the BlockData.
Get/Set the named BlockData datum.
Get/Set the BlockContainer.
NB: "Objects" here are whatever the PDFlib bindings require in PDF_* subroutines. I suspect that these are not actual objects, but it doesn't really matter.
Get/Set the current container "object"
Get/Set the current page "object"
Calls both PDF_being_page_ext and PDF_fit_pdi_page. The geometry will be adjusted to fit the imported block container.
Calls PDF_end_page_ext.
Sets the SearchPath and attempts to open BlockContainer with PDF_open_pdi_document. Returns undef on failure or the container "object" upon success. This "object" is suitable for sending to container(), above.
Calls PDF_close_pdi. Note these subroutines are not identically named.
Calls PDF_open_pdi_page. Returns undef on failure, and the page "object" upon success. This "object" is suitable for sending to current_page(), above.
Calls PDF_close_pdi_page.
Returns the number of pages in the container (which must have been set).
Returns the number of blocks on the container's current page. Both container and current_page must be set.
Returns a list of the block names on the container's current page. Both container and current_page must be set.
Returns the text string naming the font to be used for the specified block. Block name must exist, container and current_page must be set.
A wicked hack. Returns a string suitable for the last argument in PDF_fill_textblock, so long as the font for the named block is Helvetica or ZapfDingbats. For other fonts it's a crapshoot as yet.
No doubt, and only the text fillin method is supported as yet. I only have access to a couple of PDF BlockContainers and this code works reliably for those. Without Acrobat I'm unable to drum up more test cases.
Kevin Montuori <cpan@mconsultancy.us> August 2007
To install PDFLib::PPS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PDFLib::PPS
CPAN shell
perl -MCPAN -e shell install PDFLib::PPS
For more information on module installation, please visit the detailed CPAN module installation guide.