Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert HTML to PDF using pandoc?

Tags:

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).
like image 700
Chris Stryczynski Avatar asked May 25 '17 09:05

Chris Stryczynski


People also ask

Can pandoc convert HTML to PDF?

Pandoc can convert between numerous markup and word processing formats, including, but not limited to, various flavors of Markdown, HTML, LaTeX and Word docx. For the full lists of input and output formats, see the --from and --to options below. Pandoc can also produce PDF output: see creating a PDF, below.

How do I use pandoc Markdown PDF?

There are actually two steps involved in converting a Markdown file to a PDF file: The Markdown source file is converted to a LaTeX source file. Pandoc invokes the pdflatex or xelatex or other TeX command and converts the . tex source file to a PDF file.

What are pandoc files?

Pandoc includes a Haskell library and a standalone command-line program. The library includes separate modules for each input and output format, so adding a new input or output format just requires adding a new module. Pandoc is free software, released under the GPL. Copyright 2006–2022 John MacFarlane.


1 Answers

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
like image 56
scoa Avatar answered Oct 20 '22 22:10

scoa