1

I have a requirement to print PDF files to some hardware based printers, and to some Virtual PDF Printers. I am using Ghostscript for this task and programming language is C#.

The hardware printers print a PrintJob page after each document, where there are some information like Date/Time and name of the document.

The virtual printers print the document but with a different name. (Ghostscript Document)

I am unable to change/ or set a Document Name while using Ghost Script, any help is appreciated.

using (GhostscriptProcessor processor = new GhostscriptProcessor())
            {
                List<string> switches = new List<string>
            {
                //"-empty",
                "-dPrinted",
                "-dBATCH",
                "-dNOPAUSE",
                "-dNoCancel",
                "-dNOSAFER",
                "-dNumCopies=1",
                "-sDEVICE=mswinpr2",
                "-sDocumentName=" +  String.Format("\"{0}\"",Path.GetFileName(fileName)),
                "-sOutputFile=%printer%" + printerName ,
                "-f",
                fileName
            };
                processor.StartProcessing(switches.ToArray(), null);
            }

The switch 'sDocumentName' does not work, I am still seeing documents are getting printed with default name - "Ghostscript Document"

1 Answers1

0

What, precisely, do you mean by the 'Document Name' ? Where do you expect to see this ?

There is no DocumentName switch. There is a DocumentName parameter. If you read the documentation here under section 10.2 Supported options, it clearly states

Several extra options exist which cannot be set through the command-line,

and that includes DocumentName, so trying to set it from the command line clearly isn't going to achieve anything. The documentation goes on to describe how to set these parameters so if what you are trying to alter is the name presented to the Windows spooler, then you need to read that section.

KenS
  • 30,202
  • 3
  • 34
  • 51
  • As I mentioned, the physical printers print a Print Job page, where the document name is printed. I want the name of the document to be printed in that page. The switch I mentioned, is "sDocumentName" which does not do the work – Kohinoor Saha Mar 11 '19 at 04:55
  • Switches in ghostscript begin either -s or -d which is why I dropped the 's' from DocumentName, its superfluous. Lets be a little clearer; there is **no** switch -sDocumentName. There **is** a DocumetnName parameter (note the lack of -s) which, as the documentation notes, cannot be set from the command line as a switch. Since I have no clue where Windows finds the 'name of the document' (which is what you called it in your question when referring to the printed page) I've no idea if that will do what you want, but its worth trying. – KenS Mar 11 '19 at 08:19