How to print PDF on default network printer using GhostScript (gswin32c.exe) shell command

前端 未结 3 436
傲寒
傲寒 2020-11-28 07:31

I\'d like to print PDF file(s) on windows\' network printer via GhostScript.
(I dont want to use Adobe Reader)

I\'ve read gswin32c.exe which c

3条回答
  •  广开言路
    2020-11-28 07:53

    I've finally made it working and easy for debugging.
    My final method code for those interested:

        /// 
        /// Prints the PDF.
        /// 
        /// The ghost script path. Eg "C:\Program Files\gs\gs8.71\bin\gswin32c.exe"
        /// The number of copies.
        /// Name of the printer. Eg \\server_name\printer_name
        /// Name of the PDF file.
        /// 
        public bool PrintPDF (string ghostScriptPath, int numberOfCopies, string printerName, string pdfFileName) {
            ProcessStartInfo startInfo  = new ProcessStartInfo();
            startInfo.Arguments         = " -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies=" + Convert.ToString(numberOfCopies) + " -sDEVICE=ljet4 -sOutputFile=\"\\\\spool\\" + printerName + "\" \"" + pdfFileName + "\" ";
            startInfo.FileName          = ghostScriptPath; 
            startInfo.UseShellExecute = false;
    
            startInfo.RedirectStandardError = true;
            startInfo.RedirectStandardOutput = true;
    
            Process process = Process.Start(startInfo);
    
            Console.WriteLine( process.StandardError.ReadToEnd() + process.StandardOutput.ReadToEnd() );
    
            process.WaitForExit(30000);
            if (process.HasExited == false) process.Kill();
    
    
            return process.ExitCode == 0;
        }
    

提交回复
热议问题