PDF::API2::Tweaks - Assorted handy additions to PDF::API2.
PDF::API2::Tweaks provides a number of extensions to PDF::API2.
Most of the extensions deal with producing PDF overlays, to fill in forms. For example,
# Open an existing PDF file my $pdf = PDF::API2->open($form); # Retrieve an existing page my $page = $pdf->openpage(1); # Add a built-in font to the PDF my $font = $pdf->corefont('Helvetica'); # Setup text context. my $text = $page->text(); $text->font($font, 10); $text->fillcolor('#000000'); $text->strokecolor('#000000'); # So far, this is all basic PDF::API2. # The following Tweaks extension will produce a series of lines, # the first one starting at position 100,714 and subsequent lines # spaced 16 apart: $text->textlist( 100, 714, 16, <<'EOD' ); Now is the time for all good man to start using Perl EOD # Save to a file. $pdf->saveas("perl.pdf");
The following functions operate on PDF::API2::Content::Text objects. In general, these are obtained by a call to the text method on the page object.
text
Writes a list of items starting at the given coordinates and decrementing Y with D for each item. Note that items may contain newlines that will be dwimmed.
Returns the coordinates of the last item written; in scalar context the Y coordinate only.
Writes a line of text at the given coordinates.
Returns the coordinates; in scalar context the Y coordinate only.
Writes a line of text at the given coordinates, right aligned.
Writes a line of text at the given coordinates, centered.
Writes a series of items at the given coordinates, each subsequent item is horizontally offsetted by the displacement that precedes it in the list.
Returns the coordinates of the last item written; in scalar context the X coordinate only.
Writes a series of items at the given coordinates, each subsequent item is vertically offsetted by the displacement that precedes it in the list.
Writes a text at the given coordinates, each individual letter is horizontally offsetted by the displacement.
Writes a text in an rectangular area starting at X,Y and W width. Lines are broken at whitespace.
Writes a text in an rectangular area starting at X,Y and W width. Lines are broken at whitespace. A newline indicates a new paragraph start.
The following functions operate on PDF::API2::Page objects. In general, these are obtained by a call to the page method on the PDF document object.
page
Draws a grid of coordinates on the page. Lines a black for every 100, blue otherwise.
There's a small memory leak for every text object that is used. For normal use this can be ignored since you'll probably need just of couple of text objects.
To install PDF::API2::Tweaks, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PDF::API2::Tweaks
CPAN shell
perl -MCPAN -e shell install PDF::API2::Tweaks
For more information on module installation, please visit the detailed CPAN module installation guide.