HtmlToPdfConverter CefConverterSettings Sections

Hi,

When using HtmlToPdfConverter and CefConverterSettings to generate a PDF document we have an issue when trying to view the PDF in Document Outline mode.   The issue is specifically when a document section spans more than one page, when you click the heading from the document outline mode you are taken to the bottom of the section not the first page.  If you use ToC and select the section it works correctly.

The code we are using is below and I've also attached a test PDF with the issue.


CefConverterSettings converterSettings = new()

{

    Orientation = PdfPageOrientation.Portrait,

    EnableHyperLink = true,

    EnableToc = false,

    EnableJavaScript = true,

    ViewPortSize = new Size(515, 0), // 595 - 40 - 40 = 515 (A4 width minus margins)

    MediaType = MediaType.Print,

    EnableBookmarks = true,

    PdfPageSize = new SizeF(595, 842), // Set page size to A4 (210mm x 297mm)

    Margin = new Syncfusion.Pdf.Graphics.PdfMargins() { Left = 40, Right = 40, Top = 40, Bottom = 40 }

};


converterSettings.PdfHeader = AddHeader(converterSettings.PdfPageSize.Width, document.DocumentHeader, converterSettings.Margin.Left, converterSettings.Margin.Right, document.DocumentStyleSetting);

converterSettings.PdfFooter = AddFooter(converterSettings.PdfPageSize.Width, document.DocumentFooter, converterSettings.Margin.Left, converterSettings.Margin.Right, document.DocumentStyleSetting);


htmlConverter = new HtmlToPdfConverter { ConverterSettings = converterSettings };


var documentPdf = htmlConverter.Convert(htmlContent, "/");


using var documentMemoryStream = new MemoryStream();

documentPdf.Save(documentMemoryStream);

documentPdf.Close(true);



Attachment: OWLTESTAA_4962d6ac.pdf

7 Replies

KS Karmegam Seerangan Syncfusion Team November 4, 2025 12:29 PM UTC

Hi Alex,


Thank you for reporting this issue. We have reviewed the behavior on our end, and when clicking the Table of Contents (TOC) entries, the navigation correctly moves to the top of the corresponding section. We were unable to reproduce the problem you described in Document Outline mode.


To assist you further, could you please share the following details?

  • Screenshots or a sample of the expected output versus the actual behavior.
  • The input HTML or URL along with any associated resources.
  • The exact package version you are using.

These details will help us analyze the scenario more accurately and provide a suitable solution.

Regards,
Karmegam



AW Alex Whittle November 4, 2025 04:57 PM UTC

Hi, thanks for getting back to me - did you try using the attached PDF as that definitely doesn't go to the correct H2 section, try selecting 4.1 from the Document Outline mode.

I have attached the generated HTML and we are using Syncfusion.HtmlToPdfConverter.Cef.Net.Windows" Version="28.1.38"


Alex


Attachment: PDFIssue_3260e2fb.txt


AM Arumugam Muppidathi Syncfusion Team November 5, 2025 11:19 AM UTC

Hi Alex,

Thank you for providing the additional details.

We were able to replicate the reported issue on our end. Currently, we are checking this, and we will update further details on 7th November 2025.


Regards,

Arumugam M



AM Arumugam Muppidathi Syncfusion Team November 7, 2025 06:31 AM UTC

Hi Alex,

We have investigated the reported issue and found that the input HTML document contains a section titled "4.1" placed within a <thead> tag. This tag causes the section to be repeated on every page when the content spans multiple pages. As our converter generates bookmarks based on heading tags, it detects multiple instances of the "4.1" heading and selects the last occurrence for the bookmark. This behavior is expected due to the repeated header structure.


To resolve this issue, we suggest one of the following approaches:


Option 1: Move the heading outside the table


Place the "4.1" heading outside the <table> element to prevent it from being repeated:


<!-- Section heading OUTSIDE the table -->
<h2 id="section-e0642879-aaf1-44a9-9b67-0b96a9f6de04" class="section-title">4.1 TEST TEXT 1</h2>
<table>
  <tbody>
    <tr>
      <td>
        <!-- long content -->
      </td>
    </tr>
  </tbody>


Option 2: Disable repeated headers using CSS


Apply the following CSS rule to prevent the <thead> from repeating across pages:


/* This disables repeating header behavior */
table thead {
  display: table-row-group;
}


We have attached a sample including updated input HTML file and the corresponding output PDF for your reference. Please review the changes and let us know if the issue is resolved on your end. If you need any further assistance, feel free to reach out.

Regards,
Arumugam M


Attachment: HTML_to_PDF_NET_575b7a8c.zip


AW Alex Whittle November 7, 2025 11:50 AM UTC

Hi, thanks for getting back to me.  


We need the repeating heading tags across the pages so that users know which section they are reading.  Why would your converter deliberately select the last occurrence for the bookmark?  It makes no sense.  Surely the fix is to make your converter select the first instance for the bookmark, as I can't think of a single example anywhere else in a PDF document where the user wants to be taken to the last instance.



AM Arumugam Muppidathi Syncfusion Team November 10, 2025 04:08 PM UTC

Hi Alex,


We are currently reviewing your requirement and will provide an update with further details by November 12, 2025.


Regards,
Arumugam M



AM Arumugam Muppidathi Syncfusion Team November 12, 2025 11:18 AM UTC

Hi Alex,

Thank you for your patience.

 

After further analysis, as mentioned earlier, during HTML-to-PDF conversion, bookmarks are automatically generated based on the heading tags (<h1> to <h6>) present in the input HTML content. However, in your case, the heading 4.1 is placed inside a <thead> tag. This causes the heading to appear on all spanned pages, and as a result, the bookmark points to the last occurrence of the heading. This is the default behavior and cannot be changed directly.

 

To address this, we have implemented a workaround. In the provided sample, we used a <div> inside the <thead> for the 4.1 heading. This ensures the heading is preserved across all spanned pages as per your requirement.

 

HTML File:

undefined


 

For generating bookmarks, we used an <h2> tag combined with CSS styles to hide the text visually. This approach prevents layout issues and multiple visible occurrences while still allowing the text to be used for bookmark generation.

 

CSS Styles:
 

.anchor-wrap {

   font-size: 0;

   line-height: 0;

   margin: 0;

   padding: 0;

   color: #ffffff; /* page bg color */

}

 

For your reference, we have attached the sample along with the updated HTML file and the output PDF document.

 

Please review the sample and let us know if it meets your requirements. Feel free to reach out if you need any further assistance.


Regards,
Arumugam M


Attachment: HTML_to_PDF_NET_41806e53.zip

Loader.
Up arrow icon