Here is the basics of how to do it. Notice the change in the @capture region. Turning it into a multipage document, will probably need another module like shown in the second script. You can convert the ps to pdf with ImageMagic, by set('magick'=>'pdf'), and it can be done in blobs(in memory) to avoid temp ps files. Possibly there is a module that will manipulate ps directly, without the pdf conversion.
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw=MainWindow->new(-title=>"Print out the canvas"); my $c=$mw->Scrolled("Canvas")->pack(-expand=>1,-fill=>'both'); my $canvas=$c->Subwidget("canvas"); $canvas->createLine(100,100,20,20,-arrow=>'both',-arrowshape=>[10,10,1 +0]); $canvas->createOval(100,80,65,75,-fill=>"blue"); $canvas->createRectangle(30,50,60,80, -fill=>"red",-width=>5); $canvas->createText(150,1100,-text=>"check postscript",-justify=>"left +"); $canvas->createOval(150,1150,300,1300,-fill=>"blue"); $canvas->createRectangle(150,1300,400,1350, -fill=>"red",-width=>5); $canvas->configure(-scrollregion=>[$canvas->bbox("all")]); $canvas->update(); my $button=$canvas->Button(-text=>"Print",-command=>\&buttonDo) ->pack(-side=>"bottom"); MainLoop; sub buttonDo{ $canvas->update; my @capture=(); my ($x0,$y0,$x1,$y1)=$canvas->bbox('all'); my $width = $x1-$x0; my $height = ($y1-$y0)/2; print "$width $height\n"; @capture=('-x'=>$x0,'-y'=>$y0,-height=>$height,-width=>$width +); $canvas -> postscript(-colormode=>'color', -file=>"$0a.ps", -rotate=>0, # -width=> 500, # -height=>500, @capture); @capture=('-x'=>$x0,'-y'=>$height ,-height=>$height,-width=>$ +width); print $y0 + ($y1-$y0/2),"\n"; $canvas -> postscript(-colormode=>'color', -file=>"$0b.ps", -rotate=>0, # -width=> 500, # -height=>500, @capture); print "saved\n"; }
#!/usr/bin/perl use warnings; use strict; use PDF::API2; my $pdf=PDF::API2->new; # Create a new top-level PDF document my $font = $pdf->corefont('Helvetica'); my $page1 = $pdf->page(); # Create 1st page $page1->mediabox(500, 700); # Set the page dimensions my $text1 = $page1->text(); $text1->translate(50, 650); # Position the text $text1->font($font,12); $text1->text("Page 1"); my $page2 = $pdf->page(); # Create 2nd page $page2->mediabox(500, 700); # Set the page dimensions my $text2 = $page2->text(); $text2->translate(50, 650); # Position the text $text2->font($font,12); $text2->text("Page 2"); $pdf->saveas("$0.pdf"); $pdf->end; exit;

I'm not really a human, but I play one on earth Remember How Lucky You Are

In reply to Re: multi-page from Tk::Canvas by zentara
in thread multi-page from Tk::Canvas by cort

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.