转换为 PDF 方法只能使用一次
Convert to PDF method only works once
我正在使用 pechkin.synchronized
从 HTML 转换为 PDF。在第一个 http 请求上它工作正常,但之后它卡在转换方法上并且之后没有做任何事情。
这是我的控制器操作方法:
public ActionResult ToPdf(int id)
{
var order = _orderBll.GetById(id);
var viewHtml = order.Body;
byte[] pdfBuf = new SimplePechkin(new GlobalConfig()).Convert(viewHtml);
return File(pdfBuf, "application/pdf");
}
尝试使用 SynchronizedPechkin。
参见:
- Why my Web App hangs on the "easy to use" code example below?
- Why my Web App hangs/crashes even after I've started using SynchronizedPechkin
不幸的是,Pechkin 是一个 dead project and has many unresolved issues. You can avoid these by using Tuespechkin's ThreadSafeConverter,Pechkin 的开发在那里继续进行。
示例:
IConverter converter =
new ThreadSafeConverter(
new PdfToolset(
new Win32EmbeddedDeployment(
new TempFolderDeployment())));
// Keep the converter somewhere static, or as a singleton instance!
// Do NOT run the above code more than once in the application lifecycle!
byte[] result = converter.convert(document);
我的申请也遇到了同样的问题。所以我从 Nuget 管理器下载了 Synchronized Pechkin。您的代码将如下所示:
using Pechkin;
using Pechkin.Synchronized;
public ActionResult ToPdf(int id)
{
var order = _orderBll.GetById(id);
var viewHtml = order.Body;
byte[] pdfBuf = new SynchronizedPechkin(new GlobalConfig()).Convert(viewHtml);
return File(pdfBuf, "application/pdf");
}
我正在使用 pechkin.synchronized
从 HTML 转换为 PDF。在第一个 http 请求上它工作正常,但之后它卡在转换方法上并且之后没有做任何事情。
这是我的控制器操作方法:
public ActionResult ToPdf(int id)
{
var order = _orderBll.GetById(id);
var viewHtml = order.Body;
byte[] pdfBuf = new SimplePechkin(new GlobalConfig()).Convert(viewHtml);
return File(pdfBuf, "application/pdf");
}
尝试使用 SynchronizedPechkin。
参见:
- Why my Web App hangs on the "easy to use" code example below?
- Why my Web App hangs/crashes even after I've started using SynchronizedPechkin
不幸的是,Pechkin 是一个 dead project and has many unresolved issues. You can avoid these by using Tuespechkin's ThreadSafeConverter,Pechkin 的开发在那里继续进行。
示例:
IConverter converter =
new ThreadSafeConverter(
new PdfToolset(
new Win32EmbeddedDeployment(
new TempFolderDeployment())));
// Keep the converter somewhere static, or as a singleton instance!
// Do NOT run the above code more than once in the application lifecycle!
byte[] result = converter.convert(document);
我的申请也遇到了同样的问题。所以我从 Nuget 管理器下载了 Synchronized Pechkin。您的代码将如下所示:
using Pechkin;
using Pechkin.Synchronized;
public ActionResult ToPdf(int id)
{
var order = _orderBll.GetById(id);
var viewHtml = order.Body;
byte[] pdfBuf = new SynchronizedPechkin(new GlobalConfig()).Convert(viewHtml);
return File(pdfBuf, "application/pdf");
}