How to Convert Markdown to PDF: 5 Methods Compared (2025)
Five reliable ways to convert Markdown to PDF — browser print, Pandoc, VS Code, Marp, and cloud APIs. Pros, cons, and which to pick for your workflow.
"How do I convert this Markdown to a PDF?" is one of the most-Googled Markdown questions on the web — and there's no single right answer. The best method depends on what you're optimizing for: speed, fidelity, automation, or fancy layouts.
This guide walks through the five most reliable approaches, with concrete examples and a decision table at the end. By the time you finish, you'll know exactly which tool to reach for next time.
TL;DR
- One-off conversion? → Use the browser print method (5 seconds).
- Building a docs pipeline? → Use Pandoc.
- Live in VS Code? → Use the Markdown PDF extension.
- Making a presentation? → Use Marp.
- Batch / programmatic conversion? → Use a cloud API.
The full comparison table is at the bottom.
Method 1: Browser print
The fastest method, and the one we use ourselves at Markdown Viewer: render the Markdown to HTML in the browser, then use the browser's native Print → Save as PDF dialog.
How it works
- Open the Markdown editor.
- Paste your Markdown (or drag a
.mdfile in). - Click Export → Export PDF / Print.
- In the print dialog, choose Save as PDF.
- Click Save.
You get a PDF in 5 seconds with no install.
Pros
- Zero install — works in any modern browser.
- Private — your document never leaves your device.
- Native quality — uses your OS fonts and your browser's exact renderer.
- Free — no signup, no watermark.
Cons
- One file at a time — not great for batch jobs.
- Layout limited to print CSS — no fancy page numbers or running headers.
- Browser-dependent rendering — Chrome and Firefox occasionally diverge on edge cases.
Tips for the cleanest PDF
When the print dialog opens:
- Paper size: A4 or Letter
- Margins: Default (or 0.5"–0.75" custom)
- Scale: 90–100% (drop to 90% if a wide table is being cut off)
- Background graphics: ON if you want filled code blocks and blockquotes
- Headers and footers: off for a cleaner document
This method is the fastest path for 90% of Markdown-to-PDF tasks. Try it now: /tools/markdown-to-pdf.
Method 2: Pandoc
Pandoc is the Swiss Army knife of document conversion. It can turn Markdown into LaTeX, EPUB, DOCX, HTML, and — yes — PDF.
Install
# macOS
brew install pandoc
# Ubuntu / Debian
sudo apt install pandoc texlive-xetex
# Windows
choco install pandoc miktex
For PDF output you also need a LaTeX engine (XeLaTeX, pdfLaTeX, or wkhtmltopdf). The first time you run a conversion, the LaTeX engine downloads missing packages — be patient.
Basic usage
pandoc input.md -o output.pdf
That's it. The defaults give you a clean, professional PDF.
With syntax highlighting and custom fonts
pandoc input.md -o output.pdf \
--pdf-engine=xelatex \
--highlight-style=tango \
-V mainfont="Inter" \
-V monofont="JetBrains Mono" \
-V geometry:margin=1in
Custom templates
Pandoc supports custom LaTeX templates for company branding, headers, footers, watermarks, etc. The Eisvogel template is a great starting point for professional-looking documents.
Pros
- Most flexible — full control over output.
- Scriptable — perfect for CI / CD pipelines.
- Open source and battle-tested.
- Excellent typography — produces beautifully kerned, justified text.
Cons
- Steep install — LaTeX is a multi-gigabyte dependency.
- Learning curve — full configuration is nontrivial.
- Slow first run — LaTeX downloads packages on demand.
Pandoc is the gold standard if you're building a docs pipeline or generating PDFs at scale.
Method 3: VS Code
If you already write Markdown in VS Code, you can convert without leaving the editor.
Install
Install the Markdown PDF extension (by yzane) from the marketplace.
Convert
Right-click your .md file → Markdown PDF: Export (pdf). The PDF appears next to the Markdown file.
Configure
In settings.json:
{
"markdown-pdf.styles": ["./pdf-style.css"],
"markdown-pdf.executablePath": "",
"markdown-pdf.includeDefaultStyles": true,
"markdown-pdf.format": "A4",
"markdown-pdf.displayHeaderFooter": false
}
You can customize fonts, page size, margins, and add a custom CSS file. The extension uses Puppeteer under the hood, so the rendering matches Chrome.
Pros
- Integrated workflow — no context switch.
- Customizable with CSS.
- Free — open source extension.
Cons
- VS Code only.
- Heavy — installs a copy of Chromium.
- Occasionally slow to start.
Great option for developers who live in VS Code already.
Method 4: Marp
Marp turns Markdown into slide decks — and from there into PDF presentations.
Install
Two options: the Marp CLI for automation, or the Marp for VS Code extension for a live preview.
# CLI install
npm install -g @marp-team/marp-cli
Write a deck
Marp uses Markdown with a special slide separator (---):
---
marp: true
theme: default
---
# Welcome
A presentation written in Markdown.
---
## Why Marp?
- Markdown source
- Beautiful themes
- Export to PDF, PPTX, or HTML
---
## How does it look?
Pretty much like a real slide deck.
Convert to PDF
marp deck.md --pdf
You get a polished, animation-free PDF deck.
Pros
- Purpose-built for presentations.
- Themes are beautiful out of the box.
- Source-controllable — your slides live in git.
Cons
- Not for prose documents — Marp is presentation-shaped.
- Limited interactivity in the resulting PDF.
If you give technical talks, Marp is one of the most underrated tools in the ecosystem.
Method 5: Cloud APIs
For programmatic conversion — turning user-uploaded Markdown into PDFs in a SaaS product, generating receipts, building a markdown-to-PDF microservice — use a cloud API.
Popular options
- md-to-pdf.fly.dev — free, open-source API
- CloudConvert — broad format support, paid
- ConvertAPI — enterprise-grade, paid
- PDFShift — HTML-to-PDF that pairs well with a Markdown renderer
Example: cURL to a generic HTML-to-PDF API
curl --request POST \
--url https://api.pdfshift.io/v3/convert/pdf \
--user 'api:YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"source": "<h1>Hello world</h1><p>Generated from Markdown via a Node renderer.</p>",
"landscape": false,
"format": "A4"
}' \
--output output.pdf
The pattern: render Markdown to HTML server-side (e.g. with unified), POST the HTML to the PDF API.
Pros
- Scalable — designed for high volume.
- No infrastructure — no LaTeX, no headless browser to manage.
- Async-friendly — works in serverless and edge functions.
Cons
- Cost — usage-priced, can add up.
- Privacy — your content leaves your servers.
- Latency — round trip to the API.
This is the right answer when you need to convert thousands of documents per day.
Which method should you pick?
A decision table:
| Need | Best method | Why |
|---|---|---|
| Convert one document right now | Browser print | Fast, private, no install |
| Build a docs pipeline | Pandoc | Scriptable, batteries |
| Convert from inside VS Code | VS Code extension | Stay in your editor |
| Make a slide deck | Marp | Purpose-built for slides |
| Convert thousands of docs / day | Cloud API | Scales, no local install |
| Privacy is critical | Browser print | Never leaves your device |
| Need exact typography & branding | Pandoc + LaTeX template | Best fonts, most control |
| Need a watermark or page numbers | Pandoc or cloud API | Configurable templates |
Common Markdown-to-PDF mistakes
1. Pasting Markdown into a Word-style editor first. That destroys your formatting and re-applies inconsistent typography. Convert directly from .md.
2. Forgetting "Background graphics". In browser print dialogs, code-block backgrounds and blockquote fills disappear unless this is checked.
3. Long code lines that overflow. Markdown doesn't reflow code. Wrap manually in your source or lower the print scale to 90%.
4. Using uncommon fonts that don't embed. Stick to web-safe fonts or fonts you've actually installed in the conversion environment.
5. Forgetting to test the PDF. Always open the resulting file and skim it before sharing. Print dialogs occasionally clip the last paragraph.
Beyond PDF: the alternative formats
For 80% of "I need to share this Markdown" scenarios, PDF isn't actually the best answer:
- A hosted preview page — share a URL instead of a file. Always up to date.
- HTML download — opens in any browser, prints cleanly, way smaller than a PDF.
- DOCX — for Word users (also via Pandoc).
- EPUB — for long documents that should read on phones.
Ask whether PDF is the actual requirement, or whether a link to a rendered page would do the job better.
Try it now
Our recommendation for one-off conversions: open the Markdown editor, paste your content, click Export → Print (or visit the dedicated Markdown to PDF tool). For everything else, the table above is your roadmap.
Related articles
- Markdown to HTML — convert to clean, sanitized HTML instead
- HTML to Markdown — the reverse direction
- Markdown cheat sheet — every Markdown feature on one page
Pick the right tool for the job. For most people, that's the browser print path — fast, private, and free.
Written by Markdown Viewer Team. Found this useful? Try the editor →
Keep reading
Hand-picked articles related to this one.
Markdown vs HTML — how they differ, which is faster to write, which works where, and a practical decision framework for picking the right tool every time.
A complete reference for Discord Markdown — bold, italics, code blocks, spoilers, headers, lists, quotes, and the hidden tricks power users rely on every day.
A complete guide to adding images in Markdown: basic syntax, resizing with HTML, alignment, alt text best practices, and hosting options for GitHub READMEs, blogs, and docs.