in reply to $canvas->postscript method - unexpected result

I tried your script, and the page is blank because the postscript anchor is centered by default, and your items are at the extreme top and bottom. Additionally, if you read the perldoc for the postscript method, it states if BOTH pageheight and pagewidth are specified, pagewidth is only used..... that lops off your top and bottom from view. The following works for me, on my smaller screen.
#!/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 @coord=$canvas->bbox('all'); my $maxwidth=$coord[2]; my $maxheight=$coord[3]; $canvas->postscript( '-x'=>'0','-y'=>'0', -colormode=>'color', -file=> "$0.ps", -rotate=>0, -width=>$maxwidth, -height=>$maxheight, -pageanchor => 'n', -pageheight=>'8.0 i', #to fit my screen ); # system("lpr -S serverN-P printerN file.ps") == 0 or die $!; }

I'm not really a human, but I play one on earth CandyGram for Mongo

Replies are listed 'Best First'.
Re^2: $canvas->postscript method - unexpected result
by cta (Acolyte) on Jun 25, 2008 at 14:19 UTC
    I tried what you suggested but I can only print out the items on the top left corner and loose everything below them which are my 3 last items. How come it works for you and not for me?
    Maybe it's a problem of my printer, I'm not sure.
    Another point is the max height here is 1353 which is larger than my screen (8 i ~ 764 pixels) I suppose, so I think the pageheight option doesn't do its job to scale everything in my screen. That maybe explains why it doesn't work.
    I think of using a loop to split my canvas into multiple parts and dump them out accordingly like this :
    for (my $i='1'; $i<$maxheight; $i+=850){ ++$currentPage;print "$currentPage\n"; $canvas->postscript('-x'=>'0', '-y'=>$i, -width=>$maxwidth, -height=>850, -colormode=>'color', -file=>"$i.ps", -pageanchor=>'n', -pageheight=>'10.5 i'); system("lpr -S ilfpsc6vs01 -P nw1h305c $i.ps") == 0 or die $!; }
    What do you think?
    I know it seems goofy. The problem is I have to pipe every single ps file to the printer. I hope there might have a way to do this better.
      I'm not sure, I don't use postscript too often except to get full output and convert to a graphic like jpg, which I can scale. The pageheight option is supposed to scale things down to the page height (with a consequential width scaling). By experiment, I had to go down to 8 to see it all, even though my screen can handle 10. Maybe you need to experiment or check the settings for your printer..... maybe you have a "letter vs. A4" issue, a "landscape vs portrait issue", or something similar?

      You can always use ImageMagick to convert the full postscript to jpg(png, etc), then scale it to fit your printer's output. Sorry, I'm just not much of a printer expert. ;-(


      I'm not really a human, but I play one on earth CandyGram for Mongo
        thanks for your help.
        I think I gonna try to modify the ps code itself to see how it could be fixed.
        Now if I don't need to scale my output, do you know how to split my ps file into multiple pages?