【发布时间】:2013-08-08 17:05:38
【问题描述】:
我正在使用wkhtmltopdf 生成 PDF 文档。解决方案
here 在使用更大的数据集开始超时之前一直运行良好。现在我正在使用解决方案here 来防止Process 超时。我几乎复制/粘贴了它,并添加了以下内容:
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;
}
(该方法返回的对象写入System.Web.HttpContext.Current.Response)
结果比以前更好,因为它不会超时,但 PDF 文件上的每一页都是空白的。我已经尝试明确告诉 wkhtmltopdf 使用 utf-8 但这也不起作用。但是页面数量是正确的 - 如果我手动运行该工具并使用相同的 URL 转换为 PDF,我会得到相同数量的页面。
这里有什么问题?
【问题讨论】:
标签: c# asp.net encoding wkhtmltopdf