簡體   English   中英

Ghostscript使服務器崩潰

[英]Ghostscript crashes the server

我的問題是:我正在使用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)崩潰,這意味着文件已轉換,但重定向從未發生,僅頁面停留在加載狀態。 我必須使用“結束進程”關閉卡西尼或重新啟動IIS服務器,以便該進程再次正常工作。 我不認為問題出在服務上,因為我有一個類似的過程將一個byte []音頻文件發送到silverlight應用程序,並且一切正常,服務器永遠不會卡住,所以我認為這是因為ghostscript。 。,如果有人有什么想法。 我也正在使用elmah並且沒有錯誤報告...並且在調試時當我單擊包含轉換和過程其他部分的查看按鈕時,它沒有輸入click事件,但是轉換完成(不是重定向) ),我不知道怎么可能...,謝謝。 所以肯定是鬼腳本

更新:我將代碼更改為:

     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並注釋redirectoutput,這有時會導致失敗。 我能做什么? 什么是redirectStandardOutput及其它的作用...,在MSDN上無法理解...

更新2:將我的gswin64.exe更改為控制台應用程序的gswin64c.exe,現在我正在談論的窗口不再顯示。 沒有代碼發瘋……,至少現在還沒有。

首先,您不需要-dNOPAUSE因為-o意味着-dBATCH-dNOPAUSE但不會造成傷害。

這個問題是“間歇性”發生的嗎? 或者,如果您反復發送一個掛起(崩潰服務器?)的文件:它是否每次都掛起,或者在該特定文件中更頻繁地掛起?

如果這確實是斷斷續續的,則不可能是Ghostscript。

要將Ghostscript中的stdoutstderr捕獲到文件中,可以添加-sstdout=___.out-sstderr=___.err來查看Ghostscript是否抱怨。 如果您始終寫入相同的文件,則錯誤后的內容將告訴您gswin * .exe是否產生了任何消息。

添加-Z:還將在Ghostscript輸出中添加一些計時信息。

請注意,由於您正在使用-r300進行JPEG輸出:如果Ghostscript意外停止,則TEMP目錄中將存在兩個以te_且擴展名為.tmp 這些是為基於磁盤的“ clist”文件創建的,這些文件用於打包(300 dpi字母大小的頁面足夠大,可以超過默認的-dMaxBitmap=____值8m)。

如果您在TEMP文件夾te_XXXXX.tmp不到te_XXXXX.tmp文件的積累,則Ghostscript可能不會崩潰。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM