wkhtmltopdf - How to avoid Heading level conflict for categories and child pages in Table of Contents? - Stack Overflow

admin2025-04-17  1

I’m using wkhtmltopdf to generate a PDF from HTML, and I'm running into an issue with the table of contents. Here's the structure of my HTML:

   <h1>Sub-Category-1-1</h1>
      <h1>PageTitle-1</h1>
      <h1>PageTitle-2</h1>
<h1>Category-2</h1>
      <h1>PageTitle-1</h1>
      <h1>PageTitle-2</h1>

In the example above, both the categories (e.g., Category-1, Category-2) and their child pages (e.g., PageTitle-1, PageTitle-2) are using the same heading level . This causes a conflict in wkhtmltopdf's table of contents, as it cannot distinguish between the main categories and their child pages, leading to a confusing or incorrect hierarchy. In addition to page-title, each page's HTML content can have its own multiple headings, such as , , etc., which further complicates the situation.

How can I ensure that wkhtmltopdf correctly differentiates between categories and child pages in the table of contents, while preserving the intended hierarchy?

转载请注明原文地址:http://anycun.com/QandA/1744871640a88806.html