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

NAME

PDF::TextBlock - Easier creation of text blocks when using PDF::API2

VERSION

Version 0.01

SYNOPSIS

  use PDF::API2;
  use PDF::TextBlock;

  my $pdf = PDF::API2->new( -file => "40-demo.pdf" );
  my $tb  = PDF::TextBlock->new({
     pdf       => $pdf,
     fonts     => {
        b => PDF::TextBlock::Font->new({
           pdf  => $pdf,
           font => $pdf->corefont( 'Helvetica-Bold',    -encoding => 'latin1' ),
        }),
     },
  });
  $tb->text(
     $tb->garbledy_gook .
     ' <b>This fairly lengthy</b>, rather verbose sentence <b>is tagged</b> to appear ' .
     'in a <b>different font, specifically the one we tagged b for "bold".</b> ' .
     $tb->garbledy_gook .
     ' <href="http://www.omnihotels.com">Click here to visit Omni Hotels.</href> ' .
     $tb->garbledy_gook . "\n\n" .
     "New paragraph.\n\n" .
     "Another paragraph."
  );
  $tb->apply;
  $pdf->save;
  $pdf->end;

DESCRIPTION

Neither Rick Measham's excellent PDF::API2 tutorial nor PDF::FromHTML are able to cope with wanting some words inside a text block to be bold. This module makes that task trivial.

Simply define whatever tags you want PDF::TextBlock to honor inside the fonts hashref, and then you are free to use HTML-like markup in the text attribute and we'll render those fonts for you.

We also honor the HTML-like tag <href>. This means that we add annotation to the PDF for you which makes the word(s) you wrap in <href> clickable, and we underline those words.

Note this markup syntax is very rudimentary. We do not support HTML. Tags cannot overlap each other. There is no way to escape tags inside text().

METHODS

new

x

X position from the left of the document. Default is 20/mm.

y

Y position from the bottom of the document. Default is 238/mm.

w

Width of this text block. Default is 175/mm.

h

Height of this text block. Default is 220/mm.

lead

From Rick's tutorial. I don't know what this does. :) Default is 15/pt.

parspace

From Rick's tutorial. I don't know what this does. :) Default is 0/pt.

align

Alignment of words in the text block. Default is 'justify'. Legal values:

justify

Spreads words out evenly in the text block so that each line ends in the same spot on the right side of the text block. The last line in a paragraph (too short to fill the entire line) will be set to 'left'.

fulljustify

Like justify, except that the last line is also spread across the page. The last line can look very odd with very large gaps.

left

Aligns each line to the left.

Aligns each line to the right.

apply

The original version of this method was text_block(), which is © Rick Measham, 2004-2007. The latest version of text_block() can be found in the tutorial located at http://rick.measham.id.au/pdf-api2/ text_block() is released under the LGPL v2.1.

garbledy_gook

Returns a scalar containing a paragraph of jibberish. Used by test scripts for demonstrations.

  my $jibberish = $tb->garbledy_gook(50);

The integer is the numer of jibberish words you want returned. Default is 100.

AUTHOR

Jay Hannah, <jay at jays.net>

BUGS

align 'right' and 'center' with any markup tags is broken

This software can't currently handle those alignments with any markup tags. As written the software is in a loop calculating x position of each word, one word at a time from left to right. But in the case of aligns 'right' and 'center' we don't know the position of the first word until we know the x positions of ALL words. We need a smarter handler for this scenario. See t/30-demo.t. [BUG1]

Please report any bugs or feature requests to bug-pdf-textblock at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=PDF-TextBlock. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc PDF::TextBlock

You can also look for information at:

ACKNOWLEDGEMENTS

This module started from, and has grown on top of, Rick Measham's (aka Woosta) "Using PDF::API2" tutorial: http://rick.measham.id.au/pdf-api2/

COPYRIGHT & LICENSE

Copyright 2009 Jay Hannah, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 136:

Non-ASCII character seen before =encoding in '©'. Assuming CP1252