HakanL / WkHtmlToPdf-DotNet

C# .NET Core wrapper for wkhtmltopdf library that uses Webkit engine to convert HTML pages to PDF.
GNU Lesser General Public License v3.0
367 stars 66 forks source link

Should Update Example #59

Closed DanielKeeley closed 2 years ago

DanielKeeley commented 2 years ago

Hi,

Thanks for this nuget. Just wanted to let you know if you try to convert two documents to pdf in the same call it will hang on the 2nd conversion, with no error. You need to Dispose() the converter after it has been used.

        `var converter = new BasicConverter(new PdfTools());
        var bytes = converter.Convert(doc);
        converter.Dispose();
        return bytes;`
HakanL commented 2 years ago

Thanks for your input. The examples came from the original repo, but I'm happy to accept a PR to fix anything you see!

DanielKeeley commented 2 years ago

ah ok i'm just still trying to see why this is happening, might just be me actually

HakanL commented 2 years ago

Ok, could it be that you're trying to do something concurrently (multi-threaded)? The native library requires all calls to be single-threaded, so you need to use the SynchronizedConverted.

DanielKeeley commented 2 years ago

yep that was it, it's all working now, but I also had to put the converter as static outside of the method to have both pdfs convert properly: image

HakanL commented 2 years ago

Yep, the converter shouldn't be re-created for each request.