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).
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
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.
For this purpose you must use a setup.ps
file as in this link under section: 6.2 Supported options (device properties)
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):
-dDEVICEWIDTHPOINTS=
w
, -dDEVICEHEIGHTPOINTS=
h
(w,h=595,842 / 612,792 for A4 / letter, respectively), Ref.
-sPAPERSIZE=
size
, Ref.
-g
number1
x
number2
(number1,number2=5953,8419 / 6120,7920 for A4 / letter, respectively), Ref.
-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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With