How to convert Markdown to PDF
The quickest way is to open the file in an editor with a preview and print it to PDF. For scripts and batch jobs, use pandoc.
In the browser with Hashlite
No install needed, and math and Mermaid diagrams come out rendered.
- Open your document. Open the Hashlite editor and create a document, or import an existing .md file from the ⋯ menu with Import Markdown files.
- Check the preview. Tables, code, math and diagrams in the preview are printed as you see them.
- Choose Print / Save as PDF. Open the ⋯ (More actions) menu and choose Print / Save as PDF, or press Ctrl+P (⌘P on a Mac).
- Save as PDF. In the print dialog, pick Save as PDF as the destination and click Save.
Hashlite always prints in the light theme and avoids splitting code blocks, table rows and diagrams across pages. To remove the date and URL at the top and bottom of each page, turn off Headers and footers in the print dialog's settings.
Need a file to print later or on another computer? Choose ⋯ › Download HTML (.html). The file is self-contained and works offline; open it in any browser and print it to PDF the same way.
On the command line with pandoc
Pandoc converts between document formats. The basic command:
pandoc notes.md -o notes.pdf
By default pandoc typesets the PDF with LaTeX, so you also need a LaTeX distribution such as TeX Live (Linux, macOS) or MiKTeX (Windows). Useful variations:
# Better Unicode and system fonts
pandoc notes.md -o notes.pdf --pdf-engine=xelatex
# Smaller margins and a table of contents
pandoc notes.md -o notes.pdf -V geometry:margin=2cm --toc
# No LaTeX: render through HTML instead
pandoc notes.md -o notes.pdf --pdf-engine=wkhtmltopdf
The last one needs wkhtmltopdf installed; --pdf-engine=weasyprint is another HTML-based option. LaTeX math works out of the box with pandoc; Mermaid diagrams need a filter, otherwise they appear as code.
In VS Code
- Install the Markdown PDF extension from the Extensions view.
- Open your
.mdfile. - Open the Command Palette (Ctrl+Shift+P, or ⌘+Shift+P) and run Markdown PDF: Export (pdf).
The PDF is saved next to the Markdown file. The extension prints through Chromium, which it may download the first time you use it.
Which method to use
| Method | What you install | Best for |
|---|---|---|
| Hashlite | Nothing | One-off documents, documents with diagrams |
| pandoc | pandoc and a LaTeX engine | Batch jobs, scripts, precise typesetting |
| VS Code | VS Code and an extension | Files you already edit in VS Code |
Common problems
- Images are missing. Use full
https://URLs, or paths relative to the Markdown file. With pandoc, run it from the file's folder or pass--resource-path. - Wide tables or code are cut off. Switch the print layout to landscape, or shorten long lines.
- You need a page break. When printing from a browser, insert
<div style="break-after: page"></div>where the new page should start. With pandoc and LaTeX, use\newpage.
Try it in Hashlite: open the free editor and see the result as you type.