Mac*_*iej 10 c# printing pdf ghostscript
我想通过GhostScript在Windows的网络打印机上打印PDF文件.
(我不想使用Adobe Reader)
我已经阅读了gswin32c.exe,它可以完成这项工作.
我尝试了许多命令,并且找不到如何强制gs在我的(Windows默认)网络驱动器上打印PDF的方法.
我不需要点精确网络打印机 - 默认可以使用.但如果没有这样的选择,我也很高兴通过打印机名称.(我尝试过使用param -SDevice ="\ server_IP\printer_name",但这也不起作用......)
在Windows cmd下运行的命令:
gswin32c -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies=1 -sDEVICE=ljet4 -sOutputFile="\\spool\\\Server_Name\Printer_name" "C:\test.pdf"
Run Code Online (Sandbox Code Playgroud)
基于上面创建的方法 - 没有工作和thorws异常.(错误代码= 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;
}
Run Code Online (Sandbox Code Playgroud)
知道如何让它在C#下工作吗?
Mac*_*iej 13
我终于使其工作并且易于调试.
我感兴趣的最终方法代码:
/// <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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
38402 次 |
| 最近记录: |