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

Hello Monks,
I'd like to know if anyone here has the same problem that I'm having now.
I've created a ps file with the PostScript::Simple and for some reasons I've also imported an eps file to that ps file. The problem is when I try to print it from my GSView, it works fine. But I cannot use the lpr command to print it out.
It seems that the printer cannot interpret the ps file correctly.
Does anyone know how to fix it?
The following code is just an example that I use for testing
use PostScript::Simple; use strict; use warnings; # create an eps object my $e = new PostScript::Simple::EPS(file => "body.eps", colour=>1) +; # create a new PostScript object my $p = new PostScript::Simple(papersize => "A4", colour => 1); # create a new page $p->newpage; # add eps to the current page $p->importeps($e, 0,0); $p->output("headps.ps"); system("lpr -S serverN -P printerN headps.ps") == 0 or die $!;
Thanks in advance.
If you don't have eps file to test, use mine
http://rapidshare.com/files/130225822/body.eps.html

Replies are listed 'Best First'.
Re: create ps file with PostScript::Simple - cannot print it out?
by Khen1950fx (Canon) on Jul 16, 2008 at 21:29 UTC
      That's weird!! Because I don't see any warning.
      Besides, the eps file does contain the BBox.
      If you do
      my ($hx1, $hy1, $hx2, $hy2)= $e->get_bbox(); print " bbox coordinates ($hx1, $hy1, $hx2, $hy2) \n";
      you'll see its coordinates.
        Weird? No. I used an EPS that I've had for awhile. Evidently, it's corrupt. I tried your EPS, and yes there's a bbox. Now it comes back with "unknown option -S". Sorry.

        Update: changed -S to -H and got "lpr: success".

        Update2: changed system("lpr -H server -P printerN headps.ps) == 0 or die $!;

        to this:

        system("lpr -H server -P printerN headps.ps) or die $?;

Re: create ps file with PostScript::Simple - cannot print it out?
by almut (Canon) on Jul 17, 2008 at 16:46 UTC

    I can replicate your problem.  Seems you have to explicitly tell PostScript::Simple to not create EPS files (apparently that's the default). I.e.

    my $p = new PostScript::Simple(papersize => "A4", colour => 1, eps => 0); # <-- !

    EPS files won't have1 a PS showpage command (which tells the PS interpreter to actually print/output the internally rendered page), because they're meant for inclusion in other documents.

    GhostScript-derived programs automatically add a showpage if there isn't one already (while real printers do not) — which explains why it does work in that case...

    ___

    1 or, more precisely, they shouldn't normally contain "showpage" — at least that's the theory (in that respect, PostScript::Simple is behaving correctly — what's a bit counter-intuitive, though, is that EPS output is the default...).

    In real life, however, many programs do output a showpage even with EPS files - the one you're including does have one, for example - just in case someone wants to print the EPS file stand-alone, i.e. without wrapping it in a regular PS document. For the same reason, programs that include EPS files typically locally redefine the showpage command as a no-op (also done by PostScript::Simple), so the command doesn't cause any problems with the page being printed too early...

      Thanks so much for pointing this out
      You're right.
      I didn't know about the showpage event missing in the EPS file.

      Do you know how to scale everything in the pagesize? Even though I specified it, I still missed few lines on the top and footer.

      Again , thanks
        Do you know how to scale everything in the pagesize

        Either scale your EPS object ($e) as needed, and then place it slightly above y-pos zero (unless the origin is translated, [0,0] coincides with the physical left/bottom borders of the page (no margins), but most printers cannot fill the entire page, due to construction limits).  For example:

        my $e = new PostScript::Simple::EPS(file => "body.eps", colour=>1); $e->scale(0.95); ... $p->importeps($e, 0,40);

        Or use the alternative method importepsfile(...), which allows you to specify the lower left and upper right corner of a rectangle on the page into which the EPS content will be fit (i.e. autoscaled), e.g.

        $p->importepsfile({overlap => 1}, "body.eps", 200,40, 200,800);

        overlap => 1 keeps the aspect ratio as is, i.e. in this case, scaling will be done by the height (800 - 40 = 760), while the width (200 - 200 = 0) will be ignored.

        (BTW, the former method seems to have a bug (or peculiarity) if the lower left corner of the EPS bounding box isn't 0,0 (in your case it's 238,1 for example — which is fine per se). In that case, this bounding box offset is added to the position that you specify with importeps(). This doesn't make much sense, IMHO, as you'll need to know the bounding box coordinates to position the thing in a predictable way — which makes it unnecessarily cumbersome...   (the importepsfile() method, OTOH, does handle this correctly, apparently).)