Luke Oliff.

TIL: Converting Markdown to PDF With pandoc

·TIL·1 min read·Luke Oliff

Documentation in Markdown is easy. Sharing it with people who expect PDFs is not. pandoc bridges that gap.

pandoc docs.md -o docs.pdf

Converts a Markdown file to a styled PDF. pandoc uses LaTeX under the hood for the layout engine.

pandoc docs.md -o docs.pdf --pdf-engine=xelatex -V mainfont="Helvetica"

Use a specific PDF engine and font. xelatex handles system fonts better than the default pdflatex.

pandoc README.md CHANGELOG.md --toc -o release-notes.pdf

Merge multiple markdown files into one PDF with a table of contents. The –toc flag generates page numbers.

Is pandoc available on macOS?

brew install pandoc

Requires a LaTeX distribution like basictex for PDF output. For DOCX or HTML output no LaTeX is needed.