Shivangi17 has asked for the wisdom of the Perl Monks concerning the following question:

hi all,

i am creating PDF document using PDF::API2 and PDF::Textblock. i have created blocks successfully but when i am adding large amount of text to block, it is not adding new page.

please some one suggest me how to add pdf pages automatically when your text is larger than a page, using PDF::Textblock?

Thanks!!

my $pdf = PDF::API2->new( -file => "test1.pdf" ); my $tb= PDF::TextBlock->new({ pdf => $pdf, fonts => { b => PDF::TextBlock::Font->new({ pdf => $pdf, font => $pdf->corefont( 'Helvetica-Bold', -encoding => ' +latin1' ), #fillcolor => '#ff0000', }), }, }); $tb->text("$some text" and hyperlinks); my($endw, $ypos, $overflow)= $tb->apply(); $tb->y($ypos); $pdf->save; $pdf->end;

Replies are listed 'Best First'.
Re: Using PDF::Textblock
by roboticus (Chancellor) on Aug 07, 2014 at 10:51 UTC

    Shivangi17:

    Looking at the docs for PDF::TextBlock, the apply method returns the text that didn't fit in the block. So I'd suggest following the apply with apply in a loop to create a new page as long as overflow isn't empty. I've not used the module before, but from the docs it appears that it should be something like this:

    my ($endw, $ypos, $overflow) = $tb->apply(); while ($overflow ne '') { $tb = PDF::TextBlock->new( ... ); $tb->text("<i>Continued...</i><br/>" . $overflow); ($endw, $ypos, $overflow) = $tb->apply(); }

    Since the text on successive pages are a continuation, you may want to alter the starting position and size of your text block, as well as handle any 'continued' message(es).

    Update: Added a missing space (applyin --> apply in).

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.