Bug 687557

Summary: EndPage not called (with a reason code of 2) at end of job
Product: Ghostscript Reporter: SaGS <sags5495>
Component: PS InterpreterAssignee: Ray Johnston <ray.johnston>
Status: NOTIFIED FIXED    
Severity: normal    
Priority: P2    
Version: master   
Hardware: PC   
OS: All   
Customer: Word Size: ---
Bug Depends on:    
Bug Blocks: 688318    
Attachments: Short file to reproduce the problem.

Description SaGS 2004-07-05 10:25:29 UTC
The attached file produces only 1 page of output, but it should 
produce 2. While /EndPage is set to force printing the final, 
incomplete (= without showpage) page, it is not called at end of 
job so this page does not appear in the output. Sometimes, 
/EndPage has to accomplish non-trivial tasks, like flushing the 
last sheet of paper for n-up printing, calling pdfmark, etc.
Comment 1 SaGS 2004-07-05 10:32:47 UTC
Created attachment 784 [details]
Short file to reproduce the problem.

Command lines (Windows version):

    gswin32c -q -dNOPAUSE -dBATCH -sOutputFile=Bug687557.pdf
	     -sDEVICE=pdfwrite -c .setpdfwrite -f Bug687557.ps

and

    gswin32c -q -dNOPAUSE -dBATCH -sOutputFile=Bug687557-%d.jpg
	     -sDEVICE=jpeg Bug687557.ps
Comment 2 Ray Johnston 2004-07-19 22:46:43 UTC
The .endpage was not being invoked when GS did the final closedevice.

I haven't investigated whether or not this used to work, but the
patch makes sure that the .uninstallpagedevice gets interpreted
before the final closedevice, so the .endpage gets run.

No regression changes result.

The patch is:

*** src/imain.c 27 Oct 2003 10:45:18 -0000      1.37
--- src/imain.c 20 Jul 2004 05:45:09 -0000
***************
*** 827,832 ****
--- 827,837 ----
        if (i_ctx_p->pgs != NULL && i_ctx_p->pgs->device != NULL) {
            gx_device *pdev = i_ctx_p->pgs->device;

+           /* deactivate the device just before we close it for the last time */
+           gs_main_run_string(minst,
+               ".uninstallpagedevice "
+               "serverdict /.jobsavelevel get 0 eq {/quit} {/stop} ifelse
.systemvar exec",
+               0 , &exit_code, &error_object);
            code = gs_closedevice(pdev);
            if (code < 0)
                eprintf2("ERROR %d closing the device. See gs/src/ierrors.h for
code explanation.\n", code, i_ctx_p->pgs->device->dname);