Search code examples
xsltpdfpdf-generationwkhtmltopdf

How do I change TOC location in wkhtmltopdf output?


I need the TOC to be on the 3rd page. Apparently, if there is a way to control this, it has to be through the XSL stylesheet. All my search attempts didn't give me a clue though. Is it possible at all?

I can't use cover option since I need the header to show on both first and second pages.


Solution

  • OK I've found a way to do it using wkhtmltopdf 0.11. I've extracted the first two pages into a separate HTML document and then run it like this

    wkhtmltopdf [options] page cover.html toc --xsl-style-sheet ... input_file.html out.pdf
    

    Unfortunately it took a lot more effort than I expected, since I'm using it in a Rails application through wicked_pdf, and it doesn't play nice with the new options format, so I had to fork it and make the necessary changes as well.

    The command line generated by wicked_pdf looks like this (long paths omitted):

    "c:/program files (x86)/wkhtmltopdf/wkhtmltopdf.exe"  
       --header-html "file:///path/to/header" --footer-html "file:///path/to/footer" 
       --margin-top 20 --margin-bottom 15 --margin-left 5 --margin-right 40    page "file:///path/to/cover/page" --disable-javascript  toc --xsl-style-sheet "path/to/style/sheet"  - -