0

I have a requirement to Print a bunch of existing PDF files every day to a network Ricoh MP 4000 Printer. I need to print these using "HoldPrint" job type option. I am able to print it directly but I want it to do a hold print which does not mix up with other user's printing. I am using GhostScript 9.10 The one that directly prints (through function call from "Maciej"'s post):

" -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -qQUIET -sjobtype=holdprint -suserid=abc -dNumCopies=1 -sDEVICE=ljet4 -sOutputFile=\"\\spool\PrinterName\" \"C:\Printing\mypdffile.pdf\" "

Looks like I am overwriting the jobtype switch but not sure how to get it.

I tried different combinations but it simply does not work. Any help is greatly appreciated.

-dPrinted -dBATCH -dNOPAUSE -dNumCopies=1 -sDEVICE=ljet4 -sOutputFile=%printer%printerName "C:\Printing\mypdffile.pdf"

Update: Here is the version that worked for me.

        /*
         * Printer used: Ricoh Aficio MP 4000
         * Purpose: To print PDF files as a scheduled job to a network printer.
         * The files will be queued under a specific user id. 
         * The user prints the files under his account.
         * Pre-requisite: Install the network printer on the job server 
         * Manually configure Printer Job settings with user id 
         * and Job type set to "Hold Print" 
         */ 
        string _sourceFolder = “PDFFilesFolderPath”;
        DirectoryInfo di = new DirectoryInfo(_sourceFolder);
        var files = di.GetFiles().OrderBy(f => f.Name);
        string _printer = "BMIS"; // Printer name as seen in the Devices and Printers section
        foreach (var f in files)
        {
            PrintPDF(@"C:\Program Files\gs\gs9.10\bin\gswin32c.exe", 1, _printer, f.FullName);
        }


    /// <summary>
    /// Print PDF.
    /// </summary>
    /// <param name="ghostScriptPath">The ghost script path. Eg "C:\Program Files\gs\gs9.10\bin\gswin32c.exee"</param>
    /// <param name="numberOfCopies">The number of copies.</param>
    /// <param name="printerName">Exact name of the printer as seen under Devices and Printers.</param>
    /// <param name="pdfFileName">Name of the PDF file.</param>
    /// <returns></returns>

    public bool PrintPDF(string ghostScriptPath, int numberOfCopies, string printerName, string pdfFullFileName )
    {

        try
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.Arguments = " -dPrinted -dNoCancel=true -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies=" + Convert.ToString(numberOfCopies) + " -sDEVICE=mswinpr2 -sOutputFile=%printer%" + printerName + " \"" + pdfFullFileName + "\"";

            startInfo.FileName = ghostScriptPath;
            startInfo.UseShellExecute = false;
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            Process process = Process.Start(startInfo);
            process.WaitForExit(30000);
            if (process.HasExited == false) process.Kill();
            return process.ExitCode == 0;
        }
        catch (Exception ex)
        {
            System.Diagnostics.EventLog.WriteEntry("Application", ex.Message, EventLogEntryType.Error);
            throw;
        }
    }
Kiran Xyz
  • 63
  • 1
  • 6

1 Answers1

0

Ghostscript doesn't have a 'jobtype' switch, nor a suserid switch, so its not surprising that they have no effect. Possibly the post you reference has some more information, but I can't find any such post, maybe you can point to it (URL)

[later]

Setup.ps needs to be a PostScript file (because that's what Ghostscript understands, its a PostScript interpreter). From the documentation you want to set DocumentName, which is a member of the User Settings dictionary, so:

mark
    /UserSettings <<
        /DocumentName (My name goes in here)
    >>
    (mswinpr2) finddevice
    putdeviceprops
setdevice

The white space is just for clarity. This is lifted pretty much verbatim from the example.

So, you need to modify the 'setup.ps' you send for each job. You can either write a custom setup.ps for each one, or use the 'PostScript input' capability of GS and supply the whole content of setup.ps on the command line using the -c and -f switches. All setup.ps does is run the PostScript in there before you run your own PostScript program (assuming you put setup.ps before your PostScript program on the command line).

This is pretty nasty actually, its not the way devices are normally configured, but the mswinpr2 device was originally written by someone outside the Ghostscript team, and presumably adopted wholesale.

KenS
  • 30,202
  • 3
  • 34
  • 51
  • Thank You Ken. I found the solution partially. " -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies=" + Convert.ToString(numberOfCopies) + " -sDEVICE=mswinpr2 -sOutputFile=%printer%" + printerName + " \"" + pdfFullFileName + "\""; Only thing is I am controlling the Job type property directly at the printer through its config tab. Now the problem I have is that the all jobs in the print queue are named as Ghost script document.Searching to find to send the document names dynamically. so far no success. from gs site, its done using a setup.ps file but not sure how we send each docname! – Kiran Xyz Jan 24 '14 at 21:41
  • Here is the post I was initially referring to:http://stackoverflow.com/questions/2599925/how-to-print-pdf-on-default-network-printer-using-ghostscript-gswin32c-exe-she?rq=1 – Kiran Xyz Jan 24 '14 at 21:47
  • I'm not really sure I understand your problem, and whatever it is it doesn't sound like its anything to do with Ghostscript. If you are controlling the printer yourself then surely the job name is up to you ? Also it might help if you reference the Ghostscript documentation you are reading (the docs are supplied as HTML files, you don't need to use the website) – KenS Jan 25 '14 at 09:20
  • Sorry for not being clear. Setting up the job document name in printer settings uses the same name for all PDF files being printed but I would like to display unique name of each document in the queue. I have the screen shots but not sure how to upload it. Here is the link that gives more details of setup.ps file to give the documetname through script. http://www.ghostscript.com/doc/9.10/Devices.htm#Win section 10.2 and 10.3 – Kiran Xyz Jan 27 '14 at 13:57
  • Thank You Ken for making this clear and useful for someone down the line. I just learned that per our agency policy, only Adobe is allowed! Thought everyone internal in our team had the same knowledge of policy usage, but certainly not. Looks like I have no choice except to put-up with random failures of Adobe! Thank You for your time. – Kiran Xyz Jan 27 '14 at 18:07