背景:使用wkhtmltopdf工具將html轉換成pdf時,這個工具在進行轉換時會彈出命令行窗口顯示轉換過程,但是在項目運行時彈出服務器突然彈出控制台窗口會很奇怪,尤其是當轉換多個時。解決這個問題
修改之前的代碼
ProcessStartInfo startInfo = new ProcessStartInfo(wtHtmlToPdfEXEPath, Process process = Process.Start( process.WaitForExit();
修改之后的代碼
ProcessStartInfo startInfo = new ProcessStartInfo(wtHtmlToPdfEXEPath, switches); //設置不在新窗口中啟動新的進程 startInfo.CreateNoWindow = true; //不使用操作系統使用的shell啟動進程 startInfo.UseShellExecute = false; //將輸出信息重定向 startInfo.RedirectStandardOutput = true; Process process = Process.Start( process.WaitForExit();
