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

hmmm I'm having a problem with dumping my TK canvas to a postscript file. The ps file has data that Ghostscript can't interpret but I'm unsure what is causing this. One example is 0.000 0.000 0.000 setrgbcolor AdjustColor The term AdjustColor is not recognised but I have no idea what causes it to be created.

Has anyone else had problems creating a ps? Any ideas? Any help is appreciated.

Below is more specific info.

My platform: Linux What I'm using: use Tk; use Class::Struct; use POSIX; My Canvas: my $c = $mw -> Scrolled("Canvas", -cursor =>"crosshair") -> pack(-side => "left", -fill => 'both', -expand =>1); my $canvas = $c->Subwidget("canvas"); The Call: $canvas->postscript( -colormode => "mono", -fontmap=>"-*-Helvetica-Bold-0-Normal--*-140-*", -height =>5, -pageanchor => "center", -pageheight => 5, -pagewidth => 5, -pagex => 5, -pagey=>5, -rotate => 0, -width =>5, -x=>0, -y=>0, -file => "file.ps"); The result: %!PS-Adobe-3.0 EPSF-3.0 %%Creator: Tk Canvas Widget %%Title: Window .frame1.canvas %%CreationDate: Tue Dec 17 14:35:31 2002 %%BoundingBox: 3 3 9 9 %%Pages: 1 %%DocumentData: Clean7Bit %%Orientation: Portrait %%EndComments %%BeginSetup /CL 0 def %%EndSetup %%Page: 1 1 save 5.0 5.0 translate 1 1 scale -2 -2 translate 0 5 moveto 5 5 lineto 5 0 lineto 0 0 lineto closepath clip newpath gsave -160 165 moveto 6320 0 rlineto 0 -18320 rlineto -6320 0 rlineto clos +epath 0 setlinejoin 2 setlinecap 2 setlinewidth [] 0 setdash 0.000 0.000 0.000 setrgbcolor AdjustColor stroke grestore restore showpage %%Trailer end %%EOF

update (broquaint): moved <code> tags and added formatting

Replies are listed 'Best First'.
Re: tk canvas to postscript error
by Tanalis (Curate) on Dec 18, 2002 at 09:56 UTC
    Heys,

    I've had a quick look into this this morning - the Tk::Canvas docs state that The Postscript is created in Encapsulated Postscript form using version 3.0 of the Document Structuring Conventions.

    I'm going to (first) assume that the PostScript you've posted isn't all of your output (see later if it is). I've run your code snippets and I get some 311 lines, including a definition for a subroutine AdjustColor. If that's all your PostScript, then something is going critically wrong with your Canvas widget somewhere before the call to output the postscript. I've literally created a MainWindow, a Canvas, and used your call to output the .ps file.

    Assuming that, and looking elsewhere for a problem, there are two different formats for postscript files: EPS, and EPSI. EPS (Encapsulated Postscript), which Tk::Canvas is outputting, is a PostScript file that describes a single, self-contained page. ESPI is similar to this, but includes a graphical preview such that systems that can't directly render PostScript can still represent the file.

    According to the Ghostscript bug discussion forum (and other sources that go into this in more depth), an issue occurs with Ghostscript in that it can't correctly recognise an EPS file. Apparently it's possible to force it to display by changing the extension to .eps and (potentially) also using the -c showpage flag on the command line when loading Ghostscript. I'm not sure how far this goes to start explaining the error you're seeing, but I'm certain it wouldn't help matters at all.

    This is now fixed in versions above 7.32 beta of Ghostscript.

    A suggested fix, then, is to try saving the file with a .eps extension, perhaps using the -c showpage flag and seeing if that helps. That seems a small thing to me, and I'm not convinced it'll solve anything, but it can't hurt to try. Either that, or try a new(er) version of Ghostscript ...

    If it's not safe to assume that you're getting a much larger .ps file out, I'd suggest that you try doing what I did - make sure you can get the larger file out (as I said, I get 311 lines from your call). Ensure that you're not accidentally overwriting anything in the file. You can then slowly factor back in all the original code until you reach a point where you're again getting the reduced file out - and at that point you're in a much better position to know where your problem lies.

    If you can't get a larger file out at all, including a defintion of AdjustColor, among other things, I'd suggest that you perhaps have a bad installation of Tk::Canvas, and it might be worth looking deeper into that module.

    Hope that helps some .. I know I've learnt something today :)
    -- Foxcub

      Thanks Foxcub! hmm I was seeing just a small amount of PS code so I created a little test code as you suggested and it did not work either. So, after a little routing around, it looks like you nailed it; a bad TK install. I forgot to complie the c routines. I could still use most of the canvas features except the ps dump. Feeling pretty foolish now. Thanks again.