TooNewbie has asked for the wisdom of the Perl Monks concerning the following question:

Hi all. I'm having a bit of a problem in creating a ps. Each time I try to create a postscript the tops or sides of my canvas get trimmed while using the code below:
my @dim = $canvas->bbox("all"); my $width = ($dim[2]-$dim[0]); my $height = ($dim[3]-$dim[1]); my $ps = $canvas-> postscript( '-pagewidth' => "8 i", '-pageanchor' => "center", '-width' => $width, '-height' =>$height );
I'm guessing I either have to define a -pagex, -pagey and then anchor on "center" or set the -x and -y. The problem is how do I determine what these values are? I've used $canvas->bbox("all") to capture the dimensions of my canvas. This allowed me to set my width and height but I could not set -x,-y or the -pagex,-pagey as the dimension values are are off by some factor. below is a snip of what I have tried but it jsut makes things worse:
my @dim = $canvas->bbox("all"); my $width = ($dim[2]-$dim[0]); my $height = ($dim[3]-$dim[1]); my $pagex = ($dim[0]+$dim[2])/2; my $pagey = ($dim[1]+$dim[3])/2; my $ps = $canvas-> postscript( '-pagewidth' => "8 i", '-pageanchor' => "center", '-pagex' => $pagex, '-pagey' => $pagey, # '-x' => $dim[0], # '-y' => $dim[1], '-width' => $width, '-height' =>$height );
Does anyone know how tho convert the dim values so that I can use them in the -x,-y or -pagex,-pagey? Thanks in advance.

Replies are listed 'Best First'.
Re: Dumping Tk canvas to postscript
by tachyon (Chancellor) on Mar 12, 2004 at 23:53 UTC

    The defaults for -height and -width are the full hw size of the canvas widget so you should just be able to:

    my $ps = $canvas->postscript( '-pagewidth' => "8 i" );

    and it will x:y symetrical scale to give a result 8 inches wide and X high. I presume you have tried this? The bbox (bounding box) co-ords are noted in the docs to be *approximate* ie (Returns a list with four elements giving an approximate bounding box for all the items named by the tagOrId arguments) which appears to be what you are seeing.

    cheers

    tachyon

      Hey there hmmm sorry but I think I've mislead you a bit. The canvas is a scrolled canvas:
      $c = $main_window -> Scrolled("Canvas")-> pack(); $canvas = $c->Subwidget("canvas");
      What you suggested works great for printing out the visible portion but I want to print out the whole canvas (all the objects) hence the bbox.
      Any ideas?

      Thanks,
      toonewbie
        I think this bit from the Tk::Canvas documentation:
        Note: by default Postscript is only generated for information that appears in the canvas's window on the screen.
        may be interpreted that only the visible part could be dumped.