【发布时间】:2014-01-08 05:10:36
【问题描述】:
我正在尝试通过使用 Process() 调用 GhostScript 从 WebAPI Web 服务打印 pdf 文件
当在我的本地机器上“调试”一个 ASP.NET 应用程序时,这非常有效,但是当我使用完全相同的代码尝试通过 Web 服务(也在我的本地机器上)打印时,它不起作用。
我在 VS 中没有遇到任何异常 - 就应用程序而言,应用程序运行良好。
这是我用来调用 GhostScript 打印机的代码:
Process process = new Process();
process.StartInfo.Arguments = @" -dPrinted -dBATCH -dNOPROMPT -dNOPAUSE -dNOSAFER -q -dNumCopies=1 -sDEVICE=mswinpr2 -dNoCancel -sPAPERSIZE=a4 -sOutputFile=\\spool\\\printserver\printer c:\\test\test.pdf";
process.StartInfo.FileName = @"C:\Program Files (x86)\GPLGS\gswin32c.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
StringBuilder output = new StringBuilder();
StringBuilder error = new StringBuilder();
using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false))
using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false))
{
process.OutputDataReceived += (sender, e) => {
if (e.Data == null)
{
outputWaitHandle.Set();
}
else
{
Console.Write(e.Data);
output.AppendLine(e.Data);
}
};
process.ErrorDataReceived += (sender, e) =>
{
if (e.Data == null)
{
errorWaitHandle.Set();
}
else
{
Console.Write(e.Data);
error.AppendLine(e.Data);
}
};
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
if (process.HasExited == false) process.Kill();
return process.ExitCode == 0;
我认为这可能与未为所有用户安装的打印机有关,因此为所有用户添加了它们。我能看到的唯一另一件事是权限 - 但无法找到解决方案。
有人有什么想法吗?
提前感谢您的帮助。 :)
【问题讨论】:
标签: c# asp.net web-services pdf ghostscript