I have the following code which uses iron pdf version 2023.1.11416 in .net 6.0 project to print pdf from html. The problem is that when the html is large(about 400 pages or more) and have style/css the pdf rendering is super slow about 3 -4 minutes.
string workingDirectory = Environment.CurrentDirectory;
// This will get the current PROJECT directory
string projectDirectory =
Directory.GetParent(workingDirectory).Parent.Parent.FullName;
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.Timeout = 240; // seconds;
// renderer.RenderingOptions.RenderDelay = 60000; //milliseconds
Console.WriteLine("Pdf Print Example Starting NO Style");
var html = File.ReadAllText(projectDirectory + "\\Print_No_Style.html");
Stopwatch timer = new Stopwatch();
timer.Start();
var _pdfDoc = renderer.RenderHtmlAsPdf(html);
_pdfDoc.SaveAs(projectDirectory + "\\PDF_With_NO_Style.pdf");
timer.Stop();
Console.WriteLine($"Execution Time with NO Styling: {timer.ElapsedMilliseconds} ms");
timer.Start();
Console.WriteLine("Pdf Print Example Starting With Style");
html = File.ReadAllText(projectDirectory + "\\Print_With_Style.html");
_pdfDoc = renderer.RenderHtmlAsPdf(html);
timer.Stop();
_pdfDoc.SaveAs(projectDirectory + "\\PDF_With_Style.pdf");
Console.WriteLine($"Execution Time with Styling: {timer.ElapsedMilliseconds} ms");
Here us the htmls Print_No_Style.html " https://jsfiddle.net/helengeb/Ldh7f30s/" and Print_With_Style.html "https://jsfiddle.net/helengeb/vnap5ye3/"
The output is as below which shows rendering the html with styles is 7 times slower than the one with no styling.
Pdf Print Example Starting NO Style
No Style: Completed with Execution Time: **30471** ms
Pdf Print Example Starting With Style
With Style: Completed with Execution Time: **218754** ms