1
votes

I have created a small script to run my PS file through the windows printer driver for printout.

I use this code:

echo mark /NoCancel true /BitsPerPixel 4 /OutputFile (%printer%%PNAME%) /UserSettings ^<^</DocumentName (%MYDOCNAME%) ^>^> (mswinpr2) finddevice putdeviceprops setdevice>setup.ps

gswin32c -dNOPAUSE -dBATCH -r84 setup.ps %1

The script is creating a setup.ps file as recommended by the gs documentation for the mswinpr2 driver.

It looks like this:

   mark
   /NoCancel true
   /BitsPerPixel 4
   /OutputFile (Windows printer name)  
   /UserSettings 
   <<
      /DocumentName (the text for the job in the spooler queue)
   >>
   (mswinpr2)
   finddevice
   putdeviceprops
   setdevice

%printer% resolves to the empty string on my machine. %PNAME% is the name of the windows printer, "C364PS" for me.

The %printer%%PNAME% is taken from the documentation to give the desired target printer. To stay with the example printer it will resolve to C364PS

gs is then called as

gswin32c -dNOPAUSE -dBATCH -r84 setup.ps <name of desired ps file here>

This works as expected, regarding the printed result. But I want a silent printout, since I have chosen the printer before. Whatever I choose for %PNAME%, it will always pop up the "select printer" dialog.

I am running Windows 8.1 and tried gs 8.70 and 9.19.

If I add /QueryUser 3 to the setup.ps, the printout starts without further confirmation of the printer, but then it will only print on the default printer, not on the one selected in the /OutputFile.

What am I missing?

Update: I have checked this question's result, but it does not work for me, dialog keeps popping up: https://superuser.com/questions/807027/how-to-print-with-ghostscript-in-silent-mode

Update 2: I have now (as requested) tried a commandline, with the same result. I also tried without the %printer%, no difference here:

gswin32c -dNOPAUSE -dBATCH -dNOPROMPT -dNOQUERY -sOutputFile="%printer%C364SeriesPCL" -r84 setup.ps 151008172940@123@000001@000001@PR_CCCC_Vertragspruef_4@CCCC_CAAA.358636.ps

setup.ps is this, no linebreaks have been added:

mark /NoCancel true /BitsPerPixel 4 /OutputFile (C364SeriesPCL) /UserSettings <</DocumentName (151008172940@123@000001@000001@PR_CCCC_Vertragspruef_4@CCCC_CAAA.358636) >> (mswinpr2) finddevice putdeviceprops setdevice

Solution:

The string %printer% is actually a literal in the setup.ps /OutputFile () or on the commandline. So changing the setup.ps worked:

mark /NoCancel true 
/BitsPerPixel 4 
/OutputFile (%printer%C364SeriesPCL) 
/UserSettings <<
    /DocumentName (151008172940TBS000001000001PR_CONT_Vertragspruef_4CONT_CONT.358636) 
>> 
(mswinpr2) 
finddevice 
putdeviceprops 
setdevice

This way, the printer is found. I tried to copy the behavior with a commandline switch -sOutputFile but was not able to make the dialog go away without the setup.ps - I tried %%printer%%, but to no avail. As I am fine with the setup.ps, I am not following that further.

The root of my problem was, that the ghostscript documentation is correct, nevertheless, easily misunderstood here. Especially in the context of windows, it would not hurt to state explicitely, that %printer% is actually no env-variable, but really a string literal, that must be present in the output filename.

-sOutputFile="%printer%printer_name" Specifies which printer should be used. The printer_name should be typed exactly as it appears in the Printers control panel, including spaces.

To really answer my initial question. The commandline script must be changed, to escape the % signs in the %printer% literal:

echo mark /NoCancel true /BitsPerPixel 4 /OutputFile (%%printer%%%PNAME%) /UserSettings ^<^</DocumentName (%MYDOCNAME%) ^>^> (mswinpr2) finddevice putdeviceprops setdevice>setup.ps

gswin32c -dNOPAUSE -dBATCH -dNOPROMPT -r84 setup.ps %1

This works as initially planned.

1
First, rather than quote your script, try a command line, and then you can give an example command line that demonstrates your problem, rather than leaving us deciphering your script and wondering which % are variables whose values you haven't bothered to mention. I strongly suspect its the processing of % in a batch file (ie %printer% is being expanded, or not). However, as far as I'm aware there is NO option for silent printing, unless you are printing to the default printer. - KenS
As you have asked in such a kind voice, I will unroll the setup.ps for you. - thst
The batch command resolves all variables correctly. I can see the expected result in the setup.ps. The printjob name appears properly in the queue but the printer is not selected automatically. - thst
I'm sure you can see the final result, but (until you uploaded the setup.ps), I couldn't. However.... You've replaced the value associated with the /OutputDevice key with (WIndows printer name) which really tells me nothing. PLEASE quote an exact command line, not something you've modified. And again I would urge you to use the command line when testing, not a script. The most likely reason why mswinpr2 ahows a dialog is because it is unable to find the printer. This happens if you get the printer name wrong (ie the bit you obscured), or if you don't have a local printer with that name. - KenS
I understand, but without a full listing of the available printers on my system, you cannot judge if the text I put in is actually a name or just gibberish. I have now added the exact commandline as you requested, and for you to be able to actually really analyze this, I have added a list of printers on the system. I am really puzzled what I am doing wrong, the task seems simple enough. - thst

1 Answers

0
votes

I've moved this to an answer, because there is insufficient room in the comments.

So, what I would normally expect to see as a (simple) command line for this would be:

gswin32c -dNOPAUSE -dBATCH -dNOPROMPT -dNOQUERY -sOutputFile="%printer%C364SeriesPCL"  151008172940@123@000001@000001@PR_CCCC_Vertragspruef_4@CCCC_CAAA.358636.ps

Your command line includes -r84 which would normally set the resolution to 84 dpi, if that actually gets honoured you are going to print a horribly low resolution image of the PostScript, I very much doubt you really want that.

On top of that, you also are still sending setup.ps before your actual PostScript program. The problem with that is that setup.ps overrides the values you set on the command line. So your -sOutputFile="%printer%C364SeriesPCL" is overridden by the contents of setup.ps where you define /OutputFile (C364SeriesPCL)

Now, as I was suggesting earlier, your problem here is that the correct syntax for a printer is "%printer%printer name" and what you have in setup.ps is lacking the %printer%. I would imagine the reason that %printer% is missing is because you put it in a batch file and %printer% is being treated as an environment variable. Since it isn't set, it gets replaced by nothing.

So, I would suggest that you start off by using the command line you gave, but NOT including setup.ps and see what that does. If that works, then you know what the problem is. In order to use %printer% in a batch file you need to 'escape' the '%' which means you will need (I think) %%printer%%

Given that you have a PostScript printer (C364SeriesPS) why don't you just send the original PostScript file ? What you are doing here is having Ghostscript render the PostScript to an image (a Windows Bitmap in fact) which it then passes to the printing system, which will send the bitmap to the printer. This is slow, and involves shuffling a lot of data around, when you could just send the PostScript straight to the printer.