How to merge two postscript files together?

Syd picture Syd · Aug 10, 2010 · Viewed 29.8k times · Source

I am trying to merge two or more postscript files into one. I tried concatenation but it does not work as each postscript file may have different resource header.

Have anyone done this before? Are there any libraries (commercial or open source) out there? I do not mind C++, C# or even Java libraries.

Edited These are large postscript files (more than 200 Mb) and their purpose is only for color printing (not for online viewing).

Conclusion

  1. ps2write is not the answer as it does not support DSC.
  2. pswrite as reader pipitas has correctly pointed out produces L1 output. It is not the soluton.
  3. Using pdfwrite is workable. In this option, we convert two ps to a PDF and then convert the merged PDF to a ps. There may be a problem with this solution as there may be some information lost during the conversion. Besides the extra conversion steps take additional resources and time.
  4. If we do not need to view the output file, concatenating two postscript file together with the following line "false 0 startjob pop" inserted in between the files is also a solution. (See also this link)

In conclusion, the interim solution to merge two postscript files are option 3 or 4.

Answer

Kurt Pfeifle picture Kurt Pfeifle · Aug 10, 2010

Here is an example Ghostscript commandline, which would convert and merge the two (or more) PostScript files into one PDF in a one go:

 gswin32c.exe ^
   -o c:/path/to/output.pdf ^
   -sDEVICE=pdfwrite ^
   -dPDFSettings=/Screen ^
   [...more desired parameters (optional)...] ^
   /path/to/first.ps ^
   /path/to/second.ps ^
   /path/to/third.pdf

Edit: my first shot had falsely assumed PDF input files. It works of course with PostScript as well (or even a mix of PS/PDF)... And the output may also be PS.