Search code examples
pandoc

How to convert HTML to PDF using pandoc?


Which libraries do I need? Which command line parameters do I need to pass?

I've installed wkhtml2pdf and I've tried to run:

pandoc reports/7/report.html -t pdf -o reports/7/report.pdf

Which reports an error of:

To create a pdf with pandoc, use the latex or beamer writer and specify
an output file with .pdf extension (pandoc -t latex -o filename.pdf).

Solution

  • pdf is not a valid output format. latex and beamer (for latex slideshows) are.

    To create a pdf, use -t latex and -o myoutput.pdf. You can omit the -t argument since a .pdf in -o defaults to latex. So you can use either:

    pandoc reports/7/report.html -t latex -o reports/7/report.pdf
    

    or:

    pandoc reports/7/report.html -o reports/7/report.pdf