Search code examples
csspdfmarkdownwkhtmltopdfpandoc

How can I convert markdown to PDF using CSS with a table of contents?


I tried using the Pandoc and Wkhtmltopdf, and Wkhtmltopdf is working fine. But I am unable to get a table of contents and page numbering. Is there a way to get those using Pandoc?

Edit:

I would like to add another potential solution that has helped me. It is PagedMeda/Paged.js. I allows for the usage of PagedMedia CSS, which you can use to make a table of contents.


Solution

  • Pipe the output to wkhtmltopdf and use its table of contents producer (pandoc --toc doesn't do page numbers):

    pandoc input.md -s -t html | wkhtmltopdf toc - output.pdf