简体   繁体   English

System.Diagnostics.Process OutputDataReceived和wkhtmltopdf的问题

[英]Issues with System.Diagnostics.Process OutputDataReceived and wkhtmltopdf

I'm using wkhtmltopdf to generate PDF documents. 我正在使用wkhtmltopdf生成PDF文档。 The solution here was working perfectly until it started timing out with larger data sets. 开始对较大的数据集进行超时之前, 此处的解决方案一直运行良好。 Now I am using the solution here to prevent Process from timing out. 现在,我在这里使用解决方案来防止Process超时。 I've pretty much copy/pasted it, and added the following: 我几乎复制/粘贴了它,并添加了以下内容:

public byte[] WKHtmlToPdf(string url)
{
    int timeout = 60000;
    int returnCode = 0;
    byte[] file = new byte[932768];

    using (Process process = new Process())
    {
        // etc etc, same code as the solution from above

        // ...
        if (process.WaitForExit(timeout) &&
            outputWaitHandle.WaitOne(timeout) &&
            errorWaitHandle.WaitOne(timeout))
        {
            // Process completed. Check process.ExitCode here.
            file = Encoding.UTF8.GetBytes(output.ToString());
            returnCode = process.ExitCode;
        }
        // ...
    }

    return returnCode == 0 ? file : null;
}

(The object returned by this method is written to System.Web.HttpContext.Current.Response ) (此方法返回的对象被写入System.Web.HttpContext.Current.Response

The result is better than before in that it doesn't time out, but every page on the PDF file is blank. 结果比以前更好,因为它不会超时,但是PDF文件上的每一页都是空白的。 I've tried explicity telling wkhtmltopdf to use utf-8 but that doesn't work either. 我已经尝试过明确地告诉wkhtmltopdf使用utf-8,但这也不起作用。 The amount of pages is correct though - if I run the tool manually and use the same URL to convert to PDF, I get the same amount of pages. 但是页面数量是正确的-如果我手动运行该工具并使用相同的URL转换为PDF,则页面数量将是相同的。

What is wrong here? 怎么了

If anyone had the same issue as I did, they might want to try the solution here . 如果有人遇到和我一样的问题,他们可能想在这里尝试解决方案。 Worked flawlessly for me. 完美地为我工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM