4

I am using the following Ghostscript command to print a postscript document:

C:\Program Files\gs\gs9.14\bin>gswin64c.exe -sDEVICE=mswinpr2 testprinter.ps

This command opens a Print dialog where I can change the Printer, specify Print Range and Copies, and with Ok and Cancel buttons.

However my requirement is to make Ghostscript just print silently suppressing the Print dialog.

Is there a command switch that will let me print silently? So I can just issue the command and printer prints it.

I could not get any information from Google or other various Ghostscript docs available on the internet. So I would like to check with the friendly and knowledgeable super user community.

Chaitanya MSV
  • 285
  • 2
  • 3
  • 7

1 Answers1

9

Extracted from ghostscript documentation, MS Windows Printers

If no Windows printer name is specified in -sOutputFile, Ghostscript prompts for a Windows printer using the standard Print Setup dialog box. ...

If a Windows printer name is specified in -sOutputFile using the format "%printer%printer_name", for instance

gs ... -sOutputFile="%printer%Apple LaserWriter II NT" 

then Ghostscript attempts to open the Windows printer without prompting (except, of course, if the printer is connected to FILE:)

Depending of the how the final process should work, maybe you will also need the -dBATCH and -dNOPAUSE switches

notes: %printer% is a literal to Ghostscript but the syntax will collide with cmd parser that sees %printer% as a variable read operation.

Inside batch files the percent signs can be escaped by doubling them (%%printer%%) but in command line mode there is not any way to escape the percent sign if it is inside a quoted string (as shown in the documentation, they are needed to handle spaces in arguments).

In command line mode there are two alternatives:

  • Ensure that the printer environment variable does not exist (if it does not exist, then the read operation is not executed and the literal %printer% is keeped in the final executed command).
  • Define some environment variable so when the read operation is executed the resulting command will be correct.

Just some command line examples:

rem ensure the variable does not exist
set "printer="
gs ... -sOutputFile="%printer%Apple LaserWriter II NT"

rem store the full literal
set p=%^printer%
gs ... -sOutputFile="%p%Apple LaserWriter II NT" 

rem store the percent sign
set "p=%"
gs ... -sOutputFile="%p%printer%p%Apple LaserWriter II NT"     
MC ND
  • 1,501
  • 10
  • 13
  • 1
    Thanks a lot for your response. It worked for me/. Thsi is the full command: gswin64c.exe -sDEVICE=mswinpr2 -dBATCH -dNOPAUSE -sOutputFile="%printer%\\printServer\printerNameWith Spaces" testprinter.ps – Chaitanya MSV Sep 04 '14 at 23:01
  • If the printer name is not found, the dialog will prompt whatever you parametrize. – François Breton Oct 14 '20 at 13:46