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

别等时光非礼了梦想. 提交于 2019-12-09 12:04:38

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/10403721/how-to-remove-the-table-of-contents-from-the-table-of-contents-in-wkhtmltopdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!