The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

PDF::API2::Tweaks - Assorted handy additions to PDF::API2.

SYNOPSIS

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");

TEXT FUNCTIONS

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->textlist( X, Y, D, items )

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.

$text->textline( X, Y, line )

Writes a line of text at the given coordinates.

Returns the coordinates; in scalar context the Y coordinate only.

$text->textrline( X, Y, line )

Writes a line of text at the given coordinates, right aligned.

Returns the coordinates; in scalar context the Y coordinate only.

$text->textcline( X, Y, line )

Writes a line of text at the given coordinates, centered.

Returns the coordinates; in scalar context the Y coordinate only.

$text->texthlist( X, Y, item, [ disp, item, ... ] )

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.

$text->textvlist( X, Y, item, [ disp, item, ... ] )

Writes a series of items at the given coordinates, each subsequent item is vertically offsetted by the displacement that precedes it in the list.

Returns the coordinates of the last item written; in scalar context the Y coordinate only.

$text->textspread( X, Y, disp, item )

Writes a text at the given coordinates, each individual letter is horizontally offsetted by the displacement.

Returns the coordinates of the last item written; in scalar context the X coordinate only.

$text->textpara( X, Y, W, disp, indent, text )

Writes a text in an rectangular area starting at X,Y and W width. Lines are broken at whitespace.

Returns the coordinates of the last item written; in scalar context the Y coordinate only.

$text->textparas( X, Y, W, disp, indent, text )

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.

Returns the coordinates of the last item written; in scalar context the Y coordinate only.

PAGE FUNCTIONS

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->grid( [ spacing ] )

Draws a grid of coordinates on the page. Lines a black for every 100, blue otherwise.

BUGS

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.