How to remove a Table of Contents from a Table of Contents in WKHTMLTOPDF?

I generate pdf using WKHTMLTOPDF with the table of content option, but adds itself to the table of contents, showing that it is on page 2.

Thoughts on removing this?

+6
source share
1 answer

You have full control over the creation of TOCs using XSL style sheets to generate them. You can get the default stylesheet using the argument --dump-default-toc-xsl for wkhtmltopdf.

When you study it, you are particularly interested in the <body><h1>...</h1> H1 element and the xsl:if test="(@title!='')" test xsl:if test="(@title!='')"

For example, when I want to remove TOC self-promotion from myself, this is an important part of my stylesheet:

  stuff above <h1>My little TOC</h1> <ul><xsl:apply-templates select="outline:item/outline:item"/></ul> </body> </html> </xsl:template> <xsl:template match="outline:item"> <li> <xsl:if test="(@title!='') and (@title!='My little TOC')"> stuff below 

When you save the new TOC XSL, you need to reference it in your wkhtmltopdf arguments using something like --page-size A4 toc --xsl-style-sheet test.xsl TempFile.html TempFile.pdf .

+11
source

Source: https://habr.com/ru/post/914668/


All Articles