7

I'm trying to print PDF from command line to network printer in silenta mode.
Unfortunately, Ghost Script opens Windows printer dialog.

I use Windows 2008 R2 Server.

My command is:

gswin64c.exe -dBATCH -dNOPAUSE -dNumCopies=1 -sDEVICE=mswinpr2 -sOutputFile="%printer%MEasyCoder PC4 (203 dpi) on aino1" "pdf.pdf"

Printer name is: MEasyCoder PC4 (203 dpi) on aino1 and it is network printer attached to AINO1 computer.

Printer dialog looks like:

Windows printer dialog

In printer panel it looks like: Printer control panel

What is the right command line to avoid this dialog and print silently?

Lari13
  • 171
  • 1
  • 1
  • 3

4 Answers4

2

The correct way to print to a network printer in silent mode using GhostScript (gswin32c.exe) is to use \\spool\ and then the full UNC path on sOutput. All parameters are case senitive. Also, be sure to include double quotes.

gswin32c.exe  -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies=1 -sDEVICE=mswinpr2 -sOutputFile="\\spool\\\SRV-SBS01\iR-ADVC5030_PS_BW" "C:\Windows\Temp\~Packlist.pdf"
Jan H
  • 21
  • 2
2

I use gsprint, which uses GhostScript. You will need to download the old version 5 built by GhostGum for print capabilities. If you use the default installation settings, gsprint will be located here: C:\Program Files\Ghostgum\gsview

For your example:

gsprint -printer "\\ain01\MEasyCoder PC4 (203 dpi)" -dPDFFitPage "pdf.pdf"

Bobort
  • 220
  • 2
  • 20
2

According to the Details of Ghostscript Output Devices, MS Windows printers:

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:). Ghostscript attempts to set the Windows printer page size and orientation to match that expected by Ghostscript, but doesn't always succeed. It uses this algorithm: (not quoted here)

A sample command would be (source):

gswin64c.exe -sDEVICE=mswinpr2 -dBATCH -dNOPAUSE -sOutputFile="%printer%\\printServer\printerNameWith Spaces" testprinter.ps
harrymc
  • 455,459
  • 31
  • 526
  • 924
  • This command worked for me perfectly well. – harrymc Mar 04 '20 at 14:01
  • For me too, it only opens the window showing "printing page 1" etc. Without this window it would be even better. – xralf Mar 04 '20 at 15:22
  • Is it possible to set the job name as output file name? The job on the printer display is named as "ghostscript output", which is undesirable, when many jobs have this same name. – xralf Mar 26 '20 at 16:10
  • Is there a way to make it not spawn the dialog when the printer isn't found? I would rather is just failed to stderror and not lock up the process. – Trevor Oct 06 '21 at 13:40
-2

You have to use \\

%printer%\\ainoMEasyCoder...
Vomit IT - Chunky Mess Style
  • 40,038
  • 27
  • 84
  • 117