问题
I'm having trouble executing the following command silently in GhostScript:
-q -dBATCH -dNOPAUSE -dNODISPLAY -c "mark /NoCancel true /OutputFile (\\spool\ServerName\PrinterName) /UserSettings << /DocumentName (test)>> (mswinpr2) finddevice putdeviceprops setdevice" -f "c:\test.pdf" "c:\test2.pdf"
The command doesn't execute silently, it keeps prompting me to select a printer, so I suspect the OutputFile property may be an issue here. Before, I had another command that worked perfectly (see below), but the requirement for setting the documentName forced me to alter it:
-dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -sDEVICE=mswinpr2 -sOutputFile="\\spool\\ServerName\PrinterName" "c:\test.pdf" "c:\test2.pdf"
Can anyone point me in the right direction? Just to be clear, the command does work after confirming the printer prompt. I would prefer an inline solution as this command is called from managed code with the documentName being dynamic
回答1:
The mswinpr2 device is, to say the least, hacky and non-standard, as evidenced by the requirement to mess about with non-standard PostScript in order to set it up.
You could try leaving your original command line intact, and use this (before the input files) to set the DocumentName:
-c "currentdevice //null //false [ /UserSettings <</DocumentName (test) >> .putdeviceparams pop pop" -f
That ought to reconfigure the device after its been installed. I'm not really in a position to test this I'm afraid as your command line throws a rangecheck error for me, even when I use a valid printer.
回答2:
Turns out you need to escape the backslashes in the postscript part..
-q -dBATCH -dNOPAUSE -dNODISPLAY -c "mark /NoCancel true /OutputFile (\\\\spool\\\\\\ServerName\PrinterName) /UserSettings << /DocumentName (test)>> (mswinpr2) finddevice putdeviceprops setdevice" -f "c:\test.pdf" "c:\test2.pdf"
Above worked in console, when I incorporated it in my c# project, I had to escape these escapes again, resulting in this c# string
-q -dBATCH -dNOPAUSE -dNODISPLAY -c \"mark /NoCancel true /OutputFile (\\\\\\\\spool\\\\\\\\\\\\ServerName\\PrinterName) /UserSettings << /DocumentName (test)>> (mswinpr2) finddevice putdeviceprops setdevice\" -f \"c:\\test.pdf\" \"c:\\test2.pdf\"
Beautiful isn't it? /s
来源:https://stackoverflow.com/questions/39974159/ghostscript-doesnt-interpret-supplied-printer