in reply to Re: vertical spacing with PDF::API2
in thread vertical spacing with PDF::API2

Thanks so much for the cleaner treatment. I didn't understand that the numbers in this context are supposed to get smaller as you go down the page. And it does not give you another page automatically: you have to ask for it, but this is where I have to stop for now.

Output:

C:\cygwin64\home\Fred\pages2\list>perl list11.pl Wed, May 25, 2016 28. Don't be afraid to give up the good to go for the great. Don't be afraid to give up the good to go for the great. tasks for second page are fold sail new_name is May_25_2016.pdf
#!/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 = get_quote(); 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', 'make coconut phone', 'check provisions', 'tie knots', 'fold sail',, ); $txt->font( $font, 20 ); my $vspace = 70; while ( (@task)&&($linepos>0) ) { my $item = shift @task; my $msg = '[ ] ' . $item; drawline( $page, $linepos ); $txt->translate( 70, $linepos+10 ); $txt->text($msg); $linepos -= $vspace } say "tasks for second page are @task"; 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; } 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; }

How would a person represent an appointment in such a scheme?

Replies are listed 'Best First'.
Re^3: vertical spacing with PDF::API2
by poj (Abbot) on May 24, 2016 at 09:50 UTC

    The co-ordinates start bottom left of page. Start a new page when your line position gets to the end of the page like this.

    for my $item (@task) { my $msg = '[ ] ' . $item; drawline( $page, $linepos ); $txt->translate( 70, $linepos+10 ); $txt->text($msg); $linepos -= $vspace; if ($linepos < 0){ $page = $pdf->page; $txt = $page->text; $txt->font( $font, 20 ); $linepos = 650; } }

    You might consider a newpage sub to repeat the heading and add a page number.

    How would a person represent an appointment in such a scheme?

    Sorry but I don't understand the question

    poj

Re^3: vertical spacing with PDF::API2
by soonix (Chancellor) on May 24, 2016 at 14:32 UTC
    How would a person represent an appointment in such a scheme?
    in a first draft, you could add it to @task but you'd have to guess for the right position.
    Most calendars have different areas (e.g. columns) for tasks (without particular time) and events (on a time scale). I'd go for that, too.

      I was fine with the closure on this thread as it regarded the original subject, but if it's perl, you know that I'm thinking about my next way to represent something. What's more, I've been thinking of it in the context of re-reading _Intermediate Perl_, and so I want to replicate their development of Gilligan's Island with my Perl Daily Briefings who are destined to get lost and need a physical list so as to figure out what the heck I really had to do today as opposed to what one might think in a moment of hysteria.

      That said, let me re-state the question, how would you represent an appointment that would appear on your list for the next day?

        I'm not sure if I understood your question the way you meant it :-)

        "represent" internally? It consists of some timestamp (appointed date and time) and some text.

        How to present it to the user? That would include "where", which I addressed in my previous post - if it's for the following day, I'd simply put it at the end of the list, perhaps like
        tomorrow (Fri, Jun 03, 2016): 10:30 am - doctor's office
        That is, some heading or other kind of marker to make aware that "following are appointments", and then, one per line, time and textual info, similiar what you'd write in your pocket calendar.

        However, my general problem with your list would be that there's too much vertical space :-) (by my taste)
        I'd omit the lines between the items. Instead, I'd put one between the quote of the day and the list, and then perhaps one between the tasks and the appointment(s).