Bug 695745 - Error thrown creating one PDF out of many PS files
Summary: Error thrown creating one PDF out of many PS files
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: PDF Writer (show other bugs)
Version: 9.15
Hardware: PC Windows 7
: P4 normal
Assignee: Ken Sharp
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-17 12:02 UTC by Stefano Menci
Modified: 2014-12-18 09:03 UTC (History)
1 user (show)

See Also:
Customer:
Word Size: ---


Attachments
GS-crash (9.88 MB, application/x-zip-compressed)
2014-12-17 12:12 UTC, Stefano Menci
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Stefano Menci 2014-12-17 12:02:23 UTC
Running Ghostscript with:
  gswin64c.exe" @gsparams

With gsparams containing:
  -sDEVICE=pdfwrite -dPSFitPage -o "All.pdf" "1.ps" "2.ps" [...]

Crashes afer 135 pages and adds one page with:
  ERROR: limitcheck
  OFFENDING COMMAND: .makeoperator
  STACK:
  {--dup-- /FontType --eq-- 2 --index-- 32 --eq-- --and-- {--pop-- --pop
  -- false }{--resourcestatus-- }--ifelse-- }
  /resourcestatus 
  /resourcestatus 
  -dictionary- 
  ( Version 5.2.2)
  /Creator 
  -dictionary- 
  -dictionary- 

Attached the GS.cmd file that runs Ghostscript 6 times:
- the first one fails as described trying to create the .pdf with 404 .ps files
- the next five succeed using 100 (or less) files each (just to be sure that all the .ps files are healthy)
- the last one is like the first one, but uses also pdfmarks (just to see if there is a difference between with and without pdfmarks, there isn't)
Comment 1 Stefano Menci 2014-12-17 12:12:24 UTC
Created attachment 11382 [details]
GS-crash
Comment 2 Ken Sharp 2014-12-17 12:15:47 UTC
(In reply to stenci from comment #0)
> Running Ghostscript with:
>   gswin64c.exe" @gsparams
> 
> With gsparams containing:
>   -sDEVICE=pdfwrite -dPSFitPage -o "All.pdf" "1.ps" "2.ps" [...]
> 
> Crashes afer 135 pages and adds one page with:
>   ERROR: limitcheck
>   OFFENDING COMMAND: .makeoperator
>   STACK:
>   {--dup-- /FontType --eq-- 2 --index-- 32 --eq-- --and-- {--pop-- --pop
>   -- false }{--resourcestatus-- }--ifelse-- }
>   /resourcestatus 
>   /resourcestatus 
>   -dictionary- 
>   ( Version 5.2.2)
>   /Creator 
>   -dictionary- 
>   -dictionary- 

This is not a crash, it a graceful exit under an error condition.
Comment 3 Chris Liddell (chrisl) 2014-12-17 13:02:11 UTC
The problem is that because all the input files originate from the PScript5.dll, we repeatedly apply the "hook" to disable Type 32 fonts, which relies on .makeopeator. That results in overflowing the operator table.

A solution, for Ken's perusal/approval would be:
http://git.ghostscript.com/?p=user/chrisl/ghostpdl.git;a=commitdiff;h=06a462093e
Comment 4 Ken Sharp 2014-12-17 13:04:38 UTC
Beat me to it Chris :-) I'll peruse the patch in detail tomorrow though I can't see any immediate problems.

I would say that this isn't really a great way to run Ghostscript though.
Comment 5 Stefano Menci 2014-12-17 13:34:55 UTC
Why isn't this a good way to run Ghostscript?

I use the same VBA macro to generate .ps files with Excel, CAD, CAM, and other software using the GhostscriptPDF printer, then I put everything together. I have successfully generated .pdf files with 1500 .ps files in the past, and now it fails with 150.

I have recently upgraded from 9.10 to 9.15. Perhaps the behavior has changed with the new version?
Comment 6 Ken Sharp 2014-12-17 23:55:22 UTC
(In reply to stenci from comment #5)
> Why isn't this a good way to run Ghostscript?

Because you *should* reset the interpreter between each input PostScript program. Running them this way doesn't do that, which means that the effects of earlier programs persist into the execution of later programs. Which is why you get the operator defined multiple times.


> I have recently upgraded from 9.10 to 9.15. Perhaps the behavior has changed
> with the new version?

No, its always been this way (at least, since the code in question was introduced, many years ago)
Comment 7 Chris Liddell (chrisl) 2014-12-18 01:03:42 UTC
The above fix was pushed to the central repo as this commit:
http://git.ghostscript.com/?p=ghostpdl.git;a=commitdiff;h=06a46209
Comment 8 Stefano Menci 2014-12-18 07:13:07 UTC
How do I reset the interpreter between each input PostScript program?
Comment 9 Chris Liddell (chrisl) 2014-12-18 07:19:13 UTC
You need to bound each Postscript file with Postscript save/restore operations.
Comment 10 Ken Sharp 2014-12-18 07:21:24 UTC
(In reply to Stefano Menci from comment #8)
> How do I reset the interpreter between each input PostScript program?

In your case, if you do that, then each PostScript file will be produced in a separate PDF file. In the general case, you run Ghostscript with -dJOBSERVER to instantiate a job server loop, or guard each instance with save/restore manually.


The command line example for Ghostscript (as opposed to the source or library usage) is not really amenable to this anyway, its really intended to be used to input a single PostScript program, then exit.
Comment 11 Chris Liddell (chrisl) 2014-12-18 07:32:12 UTC
It's worth noting that even encapsulating each job inside a save/restore won't actually solve the issue raised in this bug......
Comment 12 Stefano Menci 2014-12-18 08:11:52 UTC
> The command line example for Ghostscript (as opposed to the source or
> library usage) is not really amenable to this anyway, its really intended
> to be used to input a single PostScript program, then exit.

Does this mean that the workaround is to first convert all the .ps files into .pdf one by one, then to merge them into one large .pdf?
Comment 13 Ken Sharp 2014-12-18 08:14:43 UTC
(In reply to Stefano Menci from comment #12)
> > The command line example for Ghostscript (as opposed to the source or
> > library usage) is not really amenable to this anyway, its really intended
> > to be used to input a single PostScript program, then exit.
> 
> Does this mean that the workaround is to first convert all the .ps files
> into .pdf one by one, then to merge them into one large .pdf?

No, you should pick up the bug fix. My point is that running Ghostscript this way is not a hugely good idea.

Note that pdfwrite doesn't merge PDFs either.
Comment 14 Stefano Menci 2014-12-18 09:03:18 UTC
(In reply to Ken Sharp from comment #13)
> No, you should pick up the bug fix. My point is that running Ghostscript
> this way is not a hugely good idea.
> 
> Note that pdfwrite doesn't merge PDFs either.

I was trying to figure out if there is a workaround while waiting for the next release.

Has already been fixed, but I don't know how to download, compile and distribute to all my users.

Thanks for the quick fix!!