Search code examples
c#asp.net-mvcpechkintuespechkin

Convert to PDF method only works once


I'm using pechkin.synchronized to convert from HTML to PDF. On the first http request it works fine, but after that it gets stuck on the convert method and doesn't doesn't do anything after that.

Here's my controller action method:

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");
}

Solution

  • Try using SynchronizedPechkin.

    See:

    Unfortunately, Pechkin is a dead project and has many unresolved issues. You can avoid these by using Tuespechkin's ThreadSafeConverter, Pechkin's development is continuing there.

    Example:

    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);