Closed timfisher closed 7 years ago
The only way I could get this to work was by using the singleton, without the singleton it fails. Hope this helps someone
In the README you say this first:
Synchronised converter
Use this converter in multi threaded applications and web servers. Conversion tasks are saved to blocking collection and executed on a single thread.
var converter = new SynchronizedConverter(new PdfTools());
Then you mention DI, and there is no mention it is mandatory. Also the basic converter does not work at all in this way.
Changed README to be more clear on how converter should be registered in DI.
Facing the same Issue, Find my DI in Startup.cs
// In Start Up Class services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
It works for the first request, from next it hangs and no response.
Thanks in Advance.
A part from declaring the singleton in Startup.cs as indicated in the README, I had to add this to my controller:
private readonly IConverter _converter;
public MyController(IConverter converter)
{
_converter = converter;
}
private byte[] GeneratePdf(string html)
{
var doc = new HtmlToPdfDocument()
{
...
};
var pdf = _converter.Convert(doc);
return pdf;
}
I used the load unmanaged library code in a new service for each document converted. Even using freelibrary() on the libwkhtmltox.dll afterwards doesn't help as the second time it tries it fails. Is there something that could be modified with the singleton in the startup.cs?