0

I have requirement of changing DocumentName that is being printed. This document name will display in printer spool. I am using Ghostscript c# wrapper to print PDF. It shows "Ghostscript output" in printer spool list. Ghostscript documentation provides a way but I didn't manage to make it work.

Here in 10.2 section they described it. https://www.ghostscript.com/doc/9.26/Devices.htm#Win

This is what I tried to run with CLI :

gswin64c.exe "D:\setup.ps" -o "D:/test.pdf" "C:\Users\ashish\Documents\tt.pdf"

Setup.ps

mark
  /NoCancel      true                       % don't show the cancel dialog
  /BitsPerPixel  4                          % force 4 bits/pixel
  /UserSettings
    <<
      /DocumentName  (Ghostscript document) % name for the Windows spooler
      /MaxResolution 360                    % maximum document resolution
    >>
  (mswinpr2) finddevice                     % select the Windows device driver
  putdeviceprops
setdevice

Result:

GPL Ghostscript 9.52 (2020-03-19)
Copyright (C) 2020 Artifex Software, Inc.  All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
| c:\Users\cjl\artifex\gs-release\9.52\ghostpdl-9.52\base\gsicc_manage.c:1888: gsicc_verify_device_profiles(): Mismatch of ICC profiles and device color model
| c:\Users\cjl\artifex\gs-release\9.52\ghostpdl-9.52\base\gsicc_manage.c:2015: gsicc_set_device_profile(): Error in device profiles
Error: /undefined in --.systemvar--
Operand stack:
   rangecheck   --dict:736/1123(ro)(G)--   .putdeviceprops
Execution stack:
   %interp_exit   .runexec2   --nostringval--   .systemvar   --nostringval--   2   %stopped_push   --nostringval--   .systemvar   .systemvar   false   1   %stopped_push   1990   1   3   %oparray_pop   1989   1   3   %oparray_pop   1977   1   3   %oparray_pop   1833   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   .systemvar   --nostringval--   2   %stopped_push   --nostringval--   1831   8   3   %oparray_pop   .systemvar   1814   8   3   %oparray_pop   .systemvar   1808   2   3   %oparray_pop
Dictionary stack:
   --dict:736/1123(ro)(G)--   --dict:0/20(G)--   --dict:75/200(L)--
Current allocation mode is local
Last OS error: Permission denied
Current file position is 430
GPL Ghostscript 9.52: Unrecoverable error, exit code 1

Thanks

Ashish Gehlot
  • 483
  • 8
  • 16
  • Just tried this and it works for me. Obviously I don't have the input file tt.pdf to test with so I just used the golfer. You should not set -o "d:/test.pdf" because (obviously) a printer doesn't take an output file name. – KenS Jul 06 '20 at 12:15
  • Hi @Kens, I tried it without -o "d:/test.pdf" but result is same as above – Ashish Gehlot Jul 06 '20 at 12:24
  • Well, it works for me with or without the -o. My suggestion would be to remove settings from 'setup.ps', one at a time. Its entirely possible that one or more of those is conflicting with your printer. Obviously I don't have your printer and you haven't said waht printer you are using. Nor have you supplied the test file tt.pdf. – KenS Jul 06 '20 at 13:08
  • You can use any printer and "tt.pdf" is regular PDF file generated from "Microsoft Print to PDF". Here Uploaded tt.pdf : https://www60.zippyshare.com/v/InulChUK/file.html – Ashish Gehlot Jul 06 '20 at 13:24
  • Remove BitsPerPixel 4 from your setup.ps, this is clearly not correct for your printer, given this error message: "Mismatch of ICC profiles and device color model". If that still doesn't work then, as I said above, remove settings one at a time from setup.ps until the problem goes away. – KenS Jul 06 '20 at 13:29
  • I managed to change DocuemntName using this command but it display Print popup to choose destination printer. Don't know what am missing to do silent printing. I want to use "HP LaserJet M1005" printer. gswin64c.exe -dNOPAUSE -dBATCH -c "mark /UserSettings <> (mswinpr2) finddevice putdeviceprops setdevice" -f -sOutputFile="%printer%Test" "C:\Users\ashish\Documents\tt.pdf" – Ashish Gehlot Jul 07 '20 at 09:26
  • If you want to use a printer called 'HP LaserJet M1005' then don't tell the device to use a printer called 'Test'. In any event, I believe the command line use of -sOutputFile like this may be incompatible with the use of the setup.ps file, though I haven't checked. If it is you'll need to go back and read the documentation again. – KenS Jul 07 '20 at 10:57
  • Hi Kens, I used 'HP LaserJet M1005' instead of 'Test' It was mistake. Also I tried without -sOutputFile and using /OutputFile property as mention in documents but didn't work. Here is last command in which am struggling to print without printer popup. gswin64c.exe -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -dNoCancel -c "mark /OutputFile %printer%HP LaserJet M1005 /UserSettings <> (mswinpr2) finddevice putdeviceprops setdevice" -dPDFFitPage -dNORANGEPAGESIZE -f "C:\Users\ashish\Documents\tt.pdf" – Ashish Gehlot Jul 07 '20 at 11:19
  • Everything between -c and -f (in the "") has to be PostScript. There are two problems with what you've put, firstly % introduces a comment, so everything from that point to the end of line (or end of input) is ignored. Even if you avoid that, putting the printer name directly inline like that will cause the interpreter to interpret the printer name as PostScript tokens. Unsurprisingly there are no operators with name like HP, LaserJet or M1005 in PostScript, so they would throw an error. You need to format the printer name as a proper PostScript object. – KenS Jul 07 '20 at 13:11
  • I haven't heard from the Artifex sales team of any contact from your company yet so I'm not prepared to offer you any further technical support on this matter. As I explained previously it appears to me that your usage is not compatible with the AGPL license under which Ghostscript is distributed, so you need to seek a commercial license. Artifex will extend technical support even to evaluators so I'd suggest you make contact with them. – KenS Jul 07 '20 at 13:14

0 Answers0