我的问题是:我正在使用 ghostscript 将一些 pdf 转换为 jpeg 文件,然后将它们渲染为 silverlight 控件。我正在使用以下方法转换 pdf 文件:
public void PdfToJpg(string ghostScriptPath, string input, string output) {
timer1.Enabled = true;
//if the pdf has more than 1 file (ex. 3) then 3 jpeg files will be outputed
String ars = "-dNOPAUSE -sDEVICE=jpeg -r300 -o" + output + "-%d.jpeg " + input;
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = ars;
startInfo.FileName = ghostScriptPath;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
using (Process exeProcess = Process.Start(startInfo)) {
exeProcess.WaitForExit();
}
}
然后将页码和页面字节[]保存到字典中,会话中的字典并使用启用silverlight的服务发送它,并将它们发送到包含silverlight控件的aspx页面(使用Response.redirect(page.aspx)) . 一切正常,但有时服务器(Cassini 或 IIS)崩溃,这意味着文件已转换但不会发生重定向,只是页面保持在加载状态。我必须使用“结束进程”关闭 cassini 或重新启动 IIS 服务器,以便该进程再次工作。我不认为问题出在服务上,因为我有一个类似的过程来向 silverlight 应用程序发送一个字节 [] 的音频文件并且一切正常,服务器永远不会卡住,所以我认为这是因为 ghostscript.. ., 如果有人有一些想法。另外我正在使用elmah并且没有报告错误......并且在调试时,当我单击包含转换和过程的其他部分的查看按钮时,它不会进入点击事件但转换完成(不是重定向),我不知道这怎么可能……谢谢。所以肯定是ghostscript
更新:我将代码更改为:
using (Process convertProc = new Process()) {
convertProc.StartInfo.FileName = ghostScriptPath;
convertProc.StartInfo.Arguments = args;
//convertProc.StartInfo.UseShellExecute = false;
//convertProc.StartInfo.RedirectStandardOutput = true;
convertProc.StartInfo.CreateNoWindow = true;
convertProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
convertProc.Start();
ThreadedKill(convertProc.Id);
convertProc.PriorityClass = ProcessPriorityClass.Normal;
convertProc.WaitForExit();
}
如果 useshellexecute 和 redirectoutput 被注释,服务器有时会“疯狂”,如果不是,代码每次都运行完美,但是出现了 ghostscript 进程的窗口,我不希望这样。为了不出现,我必须评论这行或将 useshellexecute 设置为 true 并评论重定向输出,这有时会导致失败。我能做些什么?以及什么是redirectStandardOutput 以及它是什么...,在MSDN 上不明白...
更新 2:将我的 gswin64.exe 更改为 gswin64c.exe 用于控制台应用程序,现在我正在谈论的那个窗口不再显示了。没有代码疯了……,至少现在还没有……