0

We're using IronPdf to convert HTML to a PDF. Got it up and running pretty easily until I tried to add page numbers. Using the HtmlHeaderFooter with LoadStylesAndCSSFromMainHtmlDocument set to true more than doubles the rendering time.

Turning it off is an improvement, but an HTML page that takes 20 seconds to render without the footer takes 30 seconds with and another goes from 10 seconds to 16 seconds.

I thought perhaps just using TextHeaderFooters would be faster but those aren't showing up at all. Does anyone know how to get the text footer to show up correctly? Is there another property that needs to be set? Or how to get the HTML footer to not take so long?

This is a sample of the code I'm running:

            public Stream ConvertToPdf()
            {
                License.LicenseKey = "...";
    
                var chromePdfRenderer = new ChromePdfRenderer();
    
                //This is really slow.
                chromePdfRenderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter()
                {
                    HtmlFragment = "<center>{page} of {total-pages}</center>"
                };
                
                //This doesn't show up
                chromePdfRenderer.RenderingOptions.TextHeader = new TextHeaderFooter()
                {
                    CenterText = "Ola mundo;",
                    FontSize = 12,
                    Font = FontTypes.Helvetica
                };
    
    
                using var pdf = chromePdfRenderer.RenderHtmlAsPdf("<h1>Hello World<h1>");
                return pdf.Stream;
    
            }

I've also tried this approach with similar results:

var renderer = CreateRenderer(reportModel);
using var pdfDocument = renderer.RenderHtmlAsPdf(html);

//Doesn't show.
pdfDocument.AddTextHeaders(CreateTextHeaderFooter());

//Really slow
pdfDocument.AddHtmlFooters(CreateHtmlHeaderFooter());

return pdfDocument.Stream;


todji
  • 141
  • 7

1 Answers1

0

I updated to a version of IronPdf (2022.11.10347) newly released in the time since I posted my question and the time I'm writing this response. That resolved the problem with the TextHeaderFooter not showing up.

In an email exchange with the support team at Iron Pdf (who were extremely helpful) they confirmed that the TextHeaderFooters are indeed significantly faster than the HtmlHeaderFooters and to use the former for large files when rendering time is an issue.

todji
  • 141
  • 7