in reply to vertical spacing with PDF::API2
because you are placing the text at the same position
$txt->translate( 100, 650 ); $txt->text( $header, -encoding => 'utf8' ); $txt->translate( 100, 650 ); $txt->text( $quote, -encoding => 'utf8' );
Use your variable $linepos for all the elements and decrement to move down the page as required. To wrap the text you can use the paragraph method.
#!/usr/bin/perl use v5.14; use utf8; use PDF::API2; use Time::Piece; use Time::Seconds; my $t = Time::Piece->localtime + ONE_DAY; my $today = $t->strftime("%a, %b %d, %Y"); print "$today\n"; my $header = "List for $today"; my $pdf = PDF::API2->new( width => 595, # A4 dimensions in point height => 842, # 1 point = 1/72 inch ); my $page = $pdf->page; my $txt = $page->text; my $font = $pdf->corefont('Times-Roman'); #header my $linepos = 650; $txt->font( $font, 32 ); $txt->translate( 100, $linepos ); $txt->text( $header ); $linepos -= 50; #add randomtext my $quote = "A quote with a lot of words that spreads over more than one line and possibly even extends to three lines filling the box size of 400 wide 100 deep."; print "$quote\n"; $txt->font( $font, 20 ); $txt->lead(20); # line spacing $txt->translate( 100, $linepos ); $txt->paragraph($quote, 400, 100, -align => "left" ); my $overflow_text = $txt->textpos(); $linepos -= 100; my @task = ( 'wake no later than 8', 'stretch/take meds', 'make coffee/eat cereal', 'eat salad', 'bring food',, ); $txt->font( $font, 20 ); my $vspace = 70; for my $i ( 0 .. $#task ) { my $msg = '[ ] ' . $task[$i]; drawline( $page, $linepos ); $txt->translate( 70, $linepos+10 ); $txt->text($msg); $linepos -= $vspace } my $new_name = $t->strftime("%b_%d_%Y.pdf"); say "new_name is $new_name"; $pdf->saveas($new_name); sub drawline { my ( $page, $y ) = @_; my $x1 = 50; my $x2 = 550; my $line = $page->gfx; $line->linewidth(3); $line->move( $x1, $y ); $line->line( $x2, $y ); $line->stroke; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: vertical spacing with PDF::API2
by Aldebaran (Curate) on May 24, 2016 at 08:51 UTC | |
by poj (Abbot) on May 24, 2016 at 09:50 UTC | |
by soonix (Chancellor) on May 24, 2016 at 14:32 UTC | |
by Aldebaran (Curate) on Jun 02, 2016 at 03:14 UTC | |
by soonix (Chancellor) on Jun 02, 2016 at 19:23 UTC |