2016-10-20 46 views
1

複数のURLを渡してwkhtmltopdfを使用してASP.Netアプリケーションで複数ページのPDFドキュメントを生成しようとしています。wkhtmltopdf複数ページのPDF生成プロセスがハングアップする

Public Shared Function WKHtmlToPdf(ByVal url As String, ByVal OutputDir As String, ByVal OutputFileName As String) As Boolean 

    Dim blnReturn As Boolean = False 
    Dim wkhtml As String = HttpContext.Current.Server.MapPath("~/resources/wkhtmltopdf/wkhtmltopdf.exe") 
    Dim p As New Process() 

    p.StartInfo.CreateNoWindow = True 
    p.StartInfo.RedirectStandardOutput = True 
    p.StartInfo.RedirectStandardError = True 
    p.StartInfo.RedirectStandardInput = True 
    p.StartInfo.UseShellExecute = False 
    p.StartInfo.FileName = wkhtml 
    p.StartInfo.WorkingDirectory = OutputDir 

    p.StartInfo.Arguments = url & " " & OutputFileName 
    p.Start() 
    p.WaitForExit(60000) 

    Dim returnCode As Integer = p.ExitCode 
    p.Close() 

    If returnCode = 0 Then 
     blnReturn = True 
    End If 

    Return blnReturn 

End Function 

今私が午前問題は、それが次のエラーメッセージと

p.WaitForExit(60000) 

でのエラーである - ここで

が呼び出されるコードです。

Process must exit before requested information can be determined. 

しかし、このエラーが唯一の私は以上4つのまたは5のURLを渡すときに発生するようで、それはその時々より、その少ない時々、ランダムなようです。これにより、プロセスがPDFを生成するのに長い時間がかかるため、p.WaitForExitでエラーが発生します。

リクエストの制限があるのでしょうか?私は、コマンドプロンプトを直接使用するときに必要な数のURLでPDFを生成できます。

答えて

2

問題は、プロセスが通常の設定(60秒)で返されない終了コードを待っていることです。

最新バージョンを使用している場合は、「quiet」パラメータがサポートされています。これにより、終了コードが正しく返されます。

https://wkhtmltopdf.org/usage/wkhtmltopdf.txt

--disable-javascript --quiet --disable-smart-shrinking --print-media-type --margin-top 10mm --margin-bottom 10mm --margin-right 10mm --margin-left 10mm --page-size A4 "https://www.google.com" google.pdf 
関連する問題