Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Ghostscript output file (in printer spooler)

Tags:

ghostscript

I am using Ghostscript to print a PDF by command line arguments. But it shows the printed document's name as Ghostscript output in printer spooler. I want to change it to a custom name (as letter's name).

like image 781
golf89 Avatar asked Sep 10 '12 09:09

golf89


4 Answers

Please refer to the documentation in http://www.ghostscript.com/doc/9.06/Devices.htm#Win

In particular there is an example in section 10.2 with explanation of the parameters that can be specified in section 10.3. Just changing the document name can be done by:

mark /UserSettings <</DocumentName (MyDocName)>> (mswinpr2) finddevice putdeviceprops setdevice

This can be put into a file as in the example, or can be in a string on the command line following a -c option. If you use -c instead of putting the above PostScript in a setup file, put it in as the last option before -f and the input-filename.

Note: You should not specify the -sDEVICE=mswinpr2 on the command line -- the setdevice takes care of this. I tested this on my laptop with the command line:

gswin32c \
  -dNOPAUSE -dBATCH \
  -c "mark /UserSettings <</DocumentName (MyDocName)>> (mswinpr2) finddevice putdeviceprops setdevice" \
  -f examples/colorcir.ps
like image 55
Ray Johnston Avatar answered Jan 03 '23 12:01

Ray Johnston


If the sPAPERSIZE switch is ignored, perhaps it is possible to force the page size by using the appropriate switches.

The How to Use Ghostscript manual says in the section Choosing paper size:

Otherwise you can set the page size using the pair of switches

    -dDEVICEWIDTHPOINTS=w -dDEVICEHEIGHTPOINTS=h 

Where w be the desired paper width and h be the desired paper height in points (units of 1/72 of an inch).

The section Appendix: Paper sizes known to Ghostscript, the A4 size is defined as w=595 and h=842.

enter image description here

like image 32
harrymc Avatar answered Jan 03 '23 14:01

harrymc


For this purpose you must use a setup.ps file as in this link under section: 6.2 Supported options (device properties)

like image 37
golf89 Avatar answered Jan 03 '23 14:01

golf89


This provides a partial solution to the issue, which is perhaps acceptable for your needs.

The options to control the output size are (markdown inserts spaces, but there should be none):

  1. -dDEVICEWIDTHPOINTS=w, -dDEVICEHEIGHTPOINTS=h (w,h=595,842 / 612,792 for A4 / letter, respectively), Ref.

  2. -sPAPERSIZE=size, Ref.

  3. -gnumber1xnumber2 (number1,number2=5953,8419 / 6120,7920 for A4 / letter, respectively), Ref.

  4. -dDEVICEWIDTH=number1, -dDEVICEHEIGHT=number2 (number1,number2=5953,8419 / 6120,7920 for A4 / letter, respectively), Ref.

I have tested the four of them, printing a pdf file to pdf, trying to convert (letter -> A4) and (A4 -> letter). The command line I used is

gswin32c -dPDF -dBATCH -dNOPAUSE -dFIXEDMEDIA <size setting flags> -sDEVICE=pdfwrite -sOutputFile=output.pdf input.pdf

A4 -> letter always worked well.
letter -> A4 only worked for the width, so output.pdf was always 210mm x 279.4mm.

Using, e.g., -dDEVICEWIDTHPOINTS alone for letter -> A4 produced the same result.

Adding flag -dPDFFitPage was also useful for partially adapting size (in cases I want to do that).

My conclusion is that there is some bug in Ghostscript specifically related to letter -> A4 conversion. Whether this could be handled via gs_setpd.ps (e.g., this; this would still be a bug), or a crafty combination of (-dUseBleedBox, -dUseTrimBox, -dUseArtBox, -dUseCropBox) I don't know.

like image 45
sancho.s ReinstateMonicaCellio Avatar answered Jan 03 '23 13:01

sancho.s ReinstateMonicaCellio