Markdown to PDF: 3 routes that keep the formatting
By the getPDF team · Published 11 October 2026
The short answer
Markdown becomes a PDF in 3 free ways. Quickest: open the rendered file (on GitHub or in a preview) in a browser and print to Save as PDF. Nicer, inside your editor: the Markdown PDF extension in VS Code, with A4 and code highlighting by default. Repeatable: pandoc notes.md -o notes.pdf --toc -V papersize=a4 -V geometry:margin=2cm, which needs a LaTeX install.
All 3 run on your own machine (the print route only needs the rendered page). Which one fits depends on how often you will make this PDF again: once, use the browser; now and then, VS Code; for every release of a manual, pandoc in a script.
getPDF has no Markdown to PDF converter; it converts the other way (PDF to Markdown). Where it helps is after the PDF exists: page numbers for a handout, several chapters merged into 1 file.
Page numbersNumbers, header and footer, on turned pages too. Free, runs on your device.The 3 routes side by side
| Browser print | VS Code, Markdown PDF extension | pandoc | |
|---|---|---|---|
| Install | Nothing | VS Code and 1 extension | pandoc and a LaTeX engine |
| Look | The site’s or preview’s style | GitHub-like, your own CSS possible | LaTeX typesetting, or your template |
| Code highlighting | If the renderer highlights (GitHub does) | Yes, highlight.js, on by default | Yes, several styles |
| Table of contents | No | No | --toc |
| Links in the PDF | Usually clickable | Clickable | Clickable |
| Page breaks you control | CSS, where you can add it | <div class="page"></div> |
\newpage, or a chapter per top heading |
| Good for | A one-off | Notes and READMEs you export now and then | Anything you regenerate |
Route 1: print the rendered page
No install at all. You print what a renderer already drew.
- Open the rendered file. On GitHub or GitLab, open the .md file in the repository; the site renders it. For a local file, use your editor’s preview, or any viewer that opens it in a browser tab.
- Press Ctrl+P (Cmd+P on a Mac).
- Set the destination to Save as PDF. In Chrome and Edge it is the Destination list; on a Mac, the PDF menu at the bottom of the dialog.
- Open More settings: paper size A4 or Letter, margins, and untick Headers and footers if you do not want the URL and date on every page.
- Save.
The catch: the PDF looks like the website, including its column width and whatever navigation the site lets print. Look at the preview in the dialog before you save. Fine for a quick copy, not for a handout.
Route 2: VS Code with the Markdown PDF extension
VS Code’s own Markdown preview (Ctrl+Shift+V) shows the rendered file but cannot print or export it. The extension most people use for that is Markdown PDF by yzane (version 2.2.0, over 4.2 million installs on the Visual Studio Marketplace, checked on 11 October 2026).
- Install it: Extensions panel, search Markdown PDF, Install.
- Open your .md file.
- Open the command palette (Ctrl+Shift+P, Cmd+Shift+P on a Mac) and run Markdown PDF: Export (pdf).
- The PDF lands next to the .md file, with the same name.
What it does, from its Marketplace page: it renders through a Chromium-based browser (an installed Chrome or Edge, or one it downloads on first use), the paper size is A4 by default (setting markdown-pdf.format), the margins are set with markdown-pdf.margin.top and its siblings, and code is highlighted with highlight.js unless you turn markdown-pdf.highlight off. The extension also exports HTML, PNG and JPEG from the same command list.
Route 3: pandoc, for anything you will regenerate
pandoc is the free command-line converter many technical writers build their documents with. One line gives an A4 PDF with a table of contents:
pandoc notes.md -o notes.pdf --toc -V papersize=a4 -V geometry:margin=2cm
The parts, as the pandoc manual describes them (pandoc.org, checked on 11 October 2026):
--tocadds a generated table of contents from your headings.-V papersize=a4sets the paper;letteris the other common value.-V geometry:margin=2cmpasses the margin to LaTeX’s geometry package; repeat-V geometry:...for more options.-V fontsize=11ptsets the body size; the standard classes allow 10pt, 11pt and 12pt.
pandoc writes PDFs through a PDF engine, LaTeX by default, so it needs a TeX distribution (TeX Live, MiKTeX) installed. For your own fonts, or text in Greek, Cyrillic or other scripts the default engine struggles with, switch to XeLaTeX and name a font you have installed:
pandoc notes.md -o notes.pdf --toc --pdf-engine=xelatex -V mainfont="Liberation Serif" -V papersize=a4 -V geometry:margin=2cm
These commands follow the manual’s documented options; we did not run them for this page, because the laptop it was written on has no LaTeX install. Run them once on a short file before you build a 50-page manual on them.
How do I control page breaks?
Markdown has no idea of a page. A heading that lands at the bottom of page 3 with its text on page 4 is the commonest complaint. Each route has its own fix:
- pandoc: a line with only
\newpagebreaks the page (LaTeX passes it through). To start every top-level heading on a fresh page, make them chapters: add-V documentclass=report --top-level-division=chapter. - Markdown PDF in VS Code: put
<div class="page"></div>on its own line where the break goes; the extension documents that exact snippet. - Browser print: if you control the CSS (your own preview or a static site), this rule starts each top heading on a new page:
h1 { break-before: page; }
pre, table, img { break-inside: avoid; }
The second line keeps a code block, table or picture from being cut in half across 2 pages, where the browser can.
After the PDF exists: number, merge, shrink
A manual written as 1 Markdown file per chapter becomes several PDFs. Three jobs follow, and getPDF does each in your browser with nothing uploaded:
- Merge the chapters with Merge PDF: order them with Up and Down, and keep Bookmark per file on, so the result has 1 bookmark per chapter, with that chapter’s own bookmarks (pandoc makes them from your headings) nested under it.
- Number the pages with Add page numbers: pick where (Bottom centre is the default) and the format, 1 or Page 1. Numbers are added as real text.
- Compress it with Compress PDF if screenshots made it heavy. A PDF of text alone is usually small already, and the tool says so and returns it unchanged.
What these routes cannot do
The honest part:
- None of them is WYSIWYG. You see the layout only after you export. Keep a short test file for checking styles.
- Browser print is at the mercy of the site’s CSS. You cannot add a page break to GitHub’s rendering.
- pandoc’s LaTeX output looks like LaTeX. Making it look like your company’s template means writing or finding a template; that is a project, not a flag.
- Emoji and rare scripts need a font that has them, on every route.
- getPDF does not convert Markdown to PDF. We name no converter site here, because every route above already runs on your machine and keeps the file there. If you went the other way and want a PDF back as Markdown, PDF to Markdown does that on your device, and turning PDF pages into Markdown notes shows what it keeps.
Questions
What is the quickest way to turn a .md file into a PDF?
Open it where it is rendered (GitHub, GitLab, or your editor's preview in a browser) and print with Ctrl+P (Cmd+P on a Mac), Save as PDF as the destination. Nothing to install; the look is whatever the site's style is.
How do I keep syntax highlighting in the PDF?
Print from a renderer that highlights code (GitHub does), or use the Markdown PDF extension in VS Code, which highlights with highlight.js by default. pandoc highlights code too, with a choice of styles.
How do I force a page break in Markdown?
Markdown has none. With pandoc and LaTeX, a line with \newpage breaks the page, and a report class starts every top heading on a new page. With the VS Code extension, an empty div with the class page. In the browser, CSS break-before: page.
Does pandoc need anything else installed?
Yes. pandoc writes PDFs through a PDF engine, LaTeX by default, so you need a TeX distribution such as TeX Live or MiKTeX, or another engine named with --pdf-engine. Once set up, the same command makes the same PDF every time.
Can getPDF convert Markdown to PDF?
No. getPDF converts the other way, PDF to Markdown, on your device. For Markdown to PDF the routes on this page are free and local already. After the PDF exists, getPDF numbers its pages, merges chapters and compresses it, all on your device.
The tools for this job
Keep reading
- TXT to PDF: plain text into a clean, printable fileConvert a .txt file to PDF free: print from Notepad, TextEdit or the browser, or paste into Word for nicer type.
- Create a PDF from anything, free and on your deviceCreate a PDF from Word, Google Docs, a web page, an email or plain text.
- Google Docs to PDF: margins, links and pages that holdDownload a Google Doc as a PDF with File, Download, PDF Document.
- Print to PDF on Windows 11, and bring it back when it is missingPrint to PDF on Windows 11 with Ctrl+P and Microsoft Print to PDF.
- PDF to Word, Excel and text: what converts, what breaks, and how to pickConvert PDF to Word, Excel, plain text, Markdown or CSV free in your browser.
- PDF to Markdown for notes and AI tools: what carries over and what flattensConvert a PDF to Markdown for Obsidian, Notion or an AI assistant: headings, lists and tables carry over; columns and emphasis flatten.