如何使用GhostScript的(gswin32c.exe)shell命令打印在默认的网络打印机PDF [英] How to print PDF on default network printer using GhostScript (gswin32c.exe) shell command
问题描述
我想通过对窗口GhostScript的网络打印机打印PDF文件(S)。结果
(我不想用Adobe Reader)
I'd like to print PDF file(s) on windows' network printer via GhostScript.
(I dont want to use Adobe Reader)
我读过的 gswin32c.exe 哪些可以做的工作。结果
我尝试了许多命令和coudn't找到办法如何强制GS我的(Windows默认)的网络驱动器上打印PDF文件。
I've read gswin32c.exe which can do the job.
I experimented with many commands and coudn't find the way how to force gs to print PDF on my (windows default) network drive.
我不需要点确切的网络打印机相默认可以使用。但是,如果没有这样的选择,我很高兴通过打印机的名称为好。 (我试过用参数-sDEVICE =\\ SERVER_IP \\打印机名称,但这种没有工作,以及...)
I don't need point exact network printer- default can be used. But if there is no such option I'm happy to pass printer name as well. (I've tried with param -SDevice="\server_IP\printer_name" but this didnt work as well...)
命令在Windows CMD工作:
Command working under Windows cmd:
gswin32c -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies=1 -sDEVICE=ljet4 -sOutputFile="\\spool\\\Server_Name\Printer_name" "C:\test.pdf"
以上方法创建基地 - does not工作和thorws例外。 (错误code = 1)
Method created base on above - doesnt work and thorws exception. (Error code = 1)
/// <summary>
/// Prints the PDF.
/// </summary>
/// <param name="ghostScriptPath">The ghost script path. Eg "C:\Program Files\gs\gs8.71\bin\gswin32c.exe"</param>
/// <param name="numberOfCopies">The number of copies.</param>
/// <param name="printerName">Name of the printer. Eg \\server_name\printer_name</param>
/// <param name="pdfFileName">Name of the PDF file.</param>
/// <returns></returns>
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;
Process process = Process.Start(startInfo);
return process.ExitCode == 0;
}
不知道如何使它在C#工作?
Any idea how to make it working under C#?
推荐答案
我终于做到了工作,易于调试。结果
我的最后一个方法code对于那些有兴趣:
I've finally made it working and easy for debugging.
My final method code for those interested:
/// <summary>
/// Prints the PDF.
/// </summary>
/// <param name="ghostScriptPath">The ghost script path. Eg "C:\Program Files\gs\gs8.71\bin\gswin32c.exe"</param>
/// <param name="numberOfCopies">The number of copies.</param>
/// <param name="printerName">Name of the printer. Eg \\server_name\printer_name</param>
/// <param name="pdfFileName">Name of the PDF file.</param>
/// <returns></returns>
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;
}
这篇关于如何使用GhostScript的(gswin32c.exe)shell命令打印在默认的网络打印机PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!