I have attached a small test program, showing the problem. When I do a for loop and do html to pdf conversion, all is work fine, but when I run that in a parallel loop, the HtmlToPdf library give me error about the Blink binaries that is missing. Please advise.
Hi gert,
Thank you for getting back to us.
We have checked the reported issue on our end. Upon further analysis, the reported issue may occur because you're using a shared static instance of HtmlToPdfConverter across multiple threads. This instance is being accessed simultaneously in both GenerateSyncPdf and CreateSyncHeaderFooterTemplate methods when using Parallel.ForEach.
The HtmlToPdfConverter is designed to work best in single-threaded scenarios. When used in a multi-threaded environment without proper isolation, it may lead to unexpected behavior due to the internal handling of the Chromium process. This can result in errors such as "Blink files are missing" or "insufficient permission," even when the setup appears correct.
To fix this, you should create a new instance of HtmlToPdfConverter inside each method instead of using a shared static one. This ensures that each thread has its own converter and avoids conflicts. Please refer to the below code snippet:
private static void GenerateSyncPdf(int number) { var htmlSyncConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink); ... } |
Also in,
private static PdfTemplate CreateSyncHeaderFooterTemplate(...) { var htmlSyncConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink); ... } |
By making this change, your parallel PDF generation will work reliably without throwing exceptions related to Blink or Chromium.
For your reference, we have attached the working sample along with output pdf document.
Please review this information and we kindly request you to try this sample on your end and let us know the outcome. Kindly get back to us if you need any further assistance in this.
Regards,
Arumugam M
Thank you. That work, but the overhead of starting a new converter each time is very slow...
Hi Gert,
We are currently analyzing ways to reduce the HTML to PDF conversion time and will provide further details by July 7th, 2025.
Regards,
Karmegam
Hi Gert,
Thank you for waiting for our response.
We use the Chromium rendering engine internally to convert HTML to PDF documents by launching the Chromium browser in headless mode. However, launching a new browser instance each time can lead to performance issues. To address this, we support reusing the browser instance once it is launched, using the ReuseBrowserProcess property of the HtmlToPdfConverter class. You can observe the difference in behavior and performance by toggling this property between true and false. Please refer to the sample and documentation provided below.
HTML to PDF converter features in .NET PDF Library | Syncfusion
Sample: HTMLtoPDF_Performance
Kindly try the sample and get back to us if you need further assistance.
Regards,
Karmegam