1

I am trying to build a shell service that prints PDF documents using Ghostscript running under Windows. The service should run a simple command via stdin with the filename of a PDF document and use the same printer and its settings as a context.

By default, Ghostscript starts in interactive mode. The idea is to use the same Ghostscript process rather than to run gswin64c.exe on each request to the service. Only for developing and testing, the Microsoft XPS Document Writer is used to get the result in the desired XPS file, which name is selected manually. That is why I use the Ghostscript device mswinpr2. At production environment, there will be another printer.

The command to start the Ghostscript process is as follows:

gswin64c.exe -dFitPage -dNOSAFER -dNOPAUSE -q setup_xps.ps

The Ghostscript code of setup_xps.ps:

mark
  /NoCancel      true                       % don't show the cancel dialog
  /OutputFile (%printer%Microsoft XPS Document Writer)
  /PageSize [114.0 85.0]
  (mswinpr2) finddevice                     % select the Windows device driver
  putdeviceprops
setdevice

Such a setup is the only way to set OutputFile to %printer%Microsoft XPS Document Writer: gswin64c.exe v9.54 does not recognize it correctly when passing through the command line (as a result, mswinpr2 opens the standard print dialog to choose a printer).

Then, to print a PDF document: (test.pdf) run. However, the print job is left in the enqueuing state after. And the showpage command just adds a blank page to the output XPS document. It is seen when updating the printer's job queue.

The question is what PostScript or Ghostscript command (or another language) should be used to finish this print job (which closes the output XPS file gracefully), leaving in the interactive mode of the running Ghostscript process to execute further print commands like (test_2.pdf) run, (test_3.pdf) run and so on.

Aleksey F.
  • 751
  • 7
  • 19
  • 2
    If you want Ghostscript to be a job server, then you need to set it up to run in job server mode. See the documentation https://www.ghostscript.com/doc/9.54.0/Use.htm#Other_parameters. Regarding the OutputFile, this works perfectly well for me "gswin64c -sOutputFile="%printer%Microsoft XPS Document Writer" -sDEVICE=mswinpr2 -dNoCancel \ghostpdl\examples\golfer.eps" so I think you must be doing something wrong if it doesn't work for you. Note that in job server mode you will need to set up the printer separately for each job anyway, so you still need the putdeviceprops. – KenS Sep 14 '21 at 09:30

0 Answers0