Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am generating a pdf using WKHTMLTOPDF with the table of content option, but it is adding itself to the table of contents, showing that it is on page 2.

Thoughts on removing this?

like image 721
Adam D Avatar asked May 01 '12 20:05

Adam D


1 Answers

You have full control over the TOC generation using XSL stylesheets for their generation. You can get the default stylesheet used by giving the argument --dump-default-toc-xsl to wkhtmltopdf.

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

For example, when I want to remove the TOC self-reference from itself, this is the relevant 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 then need to reference it in your wkhtmltopdf arguments using something like --page-size A4 toc --xsl-style-sheet test.xsl TempFile.html TempFile.pdf.

like image 59
Joel Peltonen Avatar answered Sep 27 '22 18:09

Joel Peltonen