Batch printing PDF files on Ricoh MP 4000 printer using Ghostscript without Adobe

StackOverflow https://stackoverflow.com/questions/21338339

  •  02-10-2022
  •  | 
  •  

質問

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;
        }
    }
役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top