Hello Monks,

I'm looking for finishing touches on a perl-based list making capability by means of PDF::API2. I can't figure out the vertical spacing. I want the quote to follow the header, but as it is, it prints out on the same line. Furthermore, the text is chopped, rather than allowed to play out in paragraph form. (Maybe the mediabox methods?) Here's what I have

#!/usr/bin/perl use v5.14; use utf8; use PDF::API2; my @months = qw(January February March April May June July August September October November December); my @days = qw(Sun Mon Tue Wed Thu Fri Sat Sun); my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime(); print "$mday $months[$mon] $days[$wday]\n"; my $day = $mday + 1; my $yr = $year + 1900; my $header = "List for $days[$wday+1], $months[$mon] $day, $yr"; 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 $txt->font( $font, 32 ); $txt->translate( 100, 650 ); $txt->text( $header, -encoding => 'utf8' ); #add randomtext my $quote = get_quote(); print "$quote\n"; $txt->font( $font, 20 ); $txt->translate( 100, 650 ); $txt->text( $quote, -encoding => 'utf8' ); my @task = ( 'wake no later than 8', 'stretch/take meds', 'make coffee/eat cereal', 'eat salad', 'bring food',, ); my $line = $page->gfx; $txt->font( $font, 20 ); my $vspace = 70; for my $i ( 0 .. $#task ) { my $linepos = 500 - ( $i * $vspace ); my $msg = '[ ] ' . $task[$i]; drawline( $line, $linepos ); $txt->translate( 70, $linepos + 10 ); $txt->text($msg); } my $new_name = join( '_', $months[$mon], $day, $yr, '.pdf' ); say "new_name is $new_name"; $pdf->saveas($new_name); sub drawline { my ( $line, $y ) = @_; my $x1 = 50; my $x2 = 550; $line->linewidth(3); $line->move( $x1, $y ); $line->line( $x2, $y ); $line->stroke; } sub get_quote { use HTML::TreeBuilder 5 -weak; my $site = 'http://motivationgrid.com/50-inspirational-quotes-to-li +ve-by/'; my $tree = HTML::TreeBuilder->new_from_url($site); my @quotes; for ( $tree->look_down( _tag => 'p' ) ) { if ( ( my $t = $_->as_text ) =~ m{ ^ \d+ \. \s+ }x ) { $t =~ s{ \x{2019} }{'}gx; $t =~ s{ \xA0 }{ }gx; $t =~ s{ \x{2013} }{--}gx; push @quotes, $t; } } my $randomelement = $quotes[ rand @quotes ]; print "$randomelement\n"; $randomelement =~ s/^\d+\.\s+//; return $randomelement; }

Thanks for your comment,


In reply to vertical spacing with PDF::API2 by Aldebaran

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.