2
我試圖通過調用Ghostscript的使用方法()Ghostscript的調用與過程()在C#中的Web API Web服務
這工作完全「調試」的ASP.NET時打印從的WebAPI Web服務PDF文件應用程序,但是當我使用完全相同的代碼嘗試通過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;
。我唯一能看到的是權限 - 但無法找出解決方案。
有沒有人有任何想法?
在此先感謝您的幫助。 :)