Markdown to PDF: The Complete Conversion Guide [2026]
Markdown is the preferred writing format for developers, technical writers, and documentation teams. It is readable as raw text and renders beautifully in GitHub, GitLab, Notion, and countless other platforms. But when you need to share a document with someone outside those ecosystems — a client, a manager, a hiring committee — a .md file is not a deliverable. PDF is the universal format for shared documents.
This guide covers every practical method for converting Markdown to PDF: from zero-install browser-based approaches to command-line powerhouses like Pandoc, to IDE extensions and online converters. It also addresses the common pain points: preserving code block formatting, applying custom styles, and handling embedded images and hyperlinks in the output.
1. Why Convert Markdown to PDF?
Markdown is a source format. It requires a renderer to look like anything other than plain text with asterisks and hashes. PDF is a presentation format — it locks in layout and typography so the document looks identical regardless of the viewer’s software, operating system, or screen size.
The most common reasons to convert Markdown to PDF:
- Sharing with non-technical recipients who do not have GitHub access or Markdown viewers
- Formal deliverables such as technical specifications, proposals, or reports that need a professional appearance
- Printing — PDFs translate to print with predictable page breaks and margins
- Archival — PDF is a stable, self-contained format; a Markdown file depends on whatever renderer is available
- Resumes and CVs — many developers write their resume in Markdown for version control, then export to PDF for distribution
2. Method 1: Browser Print to PDF
The fastest method that requires no installation: render the Markdown in a browser, then print to PDF using the browser’s built-in print dialog.
Using SnapUtils Markdown Previewer
- Open the SnapUtils Markdown Previewer
- Paste your Markdown content into the editor panel
- The right panel shows the rendered preview in real time
- Press Ctrl+P (Windows/Linux) or Cmd+P (Mac) to open the Print dialog
- Change the destination to Save as PDF
- Under More Settings, set margins to Minimum and enable Background graphics
- Click Save
Print-to-PDF Tips
- Enable “Background graphics” to include code block background colors and other CSS styling
- Set paper size to A4 or Letter depending on your region
- Use Chrome rather than Firefox for more consistent rendering of complex CSS layouts
- Add a
@media printCSS rule to adjust margins and hide navigation chrome
Preview Your Markdown Before Converting
The SnapUtils Markdown Previewer renders GitHub-flavored Markdown in real time — tables, task lists, fenced code blocks, and all. Preview your document exactly as it will look, then print to PDF directly from the browser.
Open Markdown Previewer3. Method 2: Pandoc Command Line
Pandoc is the most powerful and flexible Markdown-to-PDF conversion tool available. It is a universal document converter that supports dozens of input and output formats. For PDF output, Pandoc can use multiple engines: LaTeX (pdflatex, xelatex, lualatex) for professional typesetting quality, or wkhtmltopdf, Weasyprint, or Chrome headless for HTML-based rendering.
Installation
# macOS (Homebrew)
brew install pandoc
# macOS: also install a LaTeX distribution for PDF via LaTeX
brew install --cask basictex
# Debian/Ubuntu (as administrator)
apt-get install pandoc texlive-latex-base
# Windows (Chocolatey)
choco install pandoc miktex
Basic Conversion
# Convert Markdown to PDF (LaTeX engine by default)
pandoc input.md -o output.pdf
# Specify the PDF engine explicitly
pandoc input.md -o output.pdf --pdf-engine=xelatex
# Generate a table of contents
pandoc input.md -o output.pdf --toc
YAML Frontmatter for Document Metadata
Pandoc reads YAML frontmatter at the top of your Markdown file to set document metadata and typesetting options:
---
title: "Technical Specification: Auth Module"
author: "Engineering Team"
date: "April 19, 2026"
geometry: "margin=1in"
fontsize: 12pt
mainfont: "Georgia"
monofont: "JetBrains Mono"
colorlinks: true
---
4. Method 3: VS Code Extensions
If you write Markdown in Visual Studio Code, the Markdown PDF extension by yzane is the most convenient conversion path — no terminal required. It uses a bundled Chromium instance so no additional dependencies are needed.
Install the extension from the VS Code Extensions panel (search “Markdown PDF”), then right-click in any open Markdown file and select Markdown PDF: Export (pdf). The PDF is saved alongside your .md file.
Configure output via settings.json: set markdown-pdf.styles to an array of CSS file paths, markdown-pdf.highlightStyle to control code highlighting, and markdown-pdf.format to "A4" or "Letter".
5. Method 4: Online Converters
Several online tools convert Markdown to PDF without local installation:
| Tool | Strengths | Limitations |
|---|---|---|
| dillinger.io | Real-time preview, export to PDF and HTML | Basic styling, no custom CSS |
| stackedit.io | Full-featured editor, Google Drive sync | PDF export requires account |
| md2pdf.netlify.app | Simple, fast, clean output | No custom styles |
| cloudconvert.com | Many format options, API available | Rate limits on free tier |
For sensitive documents, prefer local conversion methods (Pandoc or VS Code extension) rather than pasting content into an online tool.
6. Preserving Code Blocks and Syntax Highlighting
Code blocks are the most important elements to preserve correctly in technical documentation PDFs. There are three distinct concerns: monospace font rendering, syntax highlighting colors, and page-break behavior for long blocks.
Monospace Font
With Pandoc and LaTeX, set monofont: "JetBrains Mono" in frontmatter. With CSS-based methods, apply font-family: monospace to pre and code elements in your stylesheet.
Syntax Highlighting
Use fenced code blocks with a language identifier. With Pandoc, the --highlight-style flag controls the color theme. Available built-in themes: pygments (default), kate, monochrome, espresso, zenburn, haddock, tango.
Page Breaks
For HTML-based PDFs, add page-break-inside: avoid to the pre CSS rule to prevent short blocks from being split across pages. For very long code blocks, wrapping is unavoidable — Pandoc’s LaTeX output can be configured with breaklines=true in the listings package settings.
7. Custom CSS for Markdown PDF Styling
For HTML-based PDF conversion, you control the appearance entirely through CSS. A minimal print-optimized stylesheet sets a serif body font, uses sans-serif for headings, gives code blocks a light gray background, and appends link URLs when printing:
body {
font-family: Georgia, serif;
font-size: 11pt;
line-height: 1.7;
color: #1a1a1a;
max-width: 700px;
margin: 0 auto;
}
h1, h2, h3 { font-family: Arial, sans-serif; page-break-after: avoid; }
pre {
background: #f6f8fa;
border: 1px solid #ddd;
padding: 1em;
font-size: 9pt;
page-break-inside: avoid;
}
@media print {
a[href]:after { content: " (" attr(href) ")"; font-size: 8pt; }
}
8. Handling Images and Links in PDF Output
Local Images
Images referenced with relative paths must be accessible at that path when the conversion runs. With Pandoc, run the command from the same directory as your Markdown file, or pass --resource-path=./images. For online converters, images must be embedded as data URIs (see the data URI guide) or hosted at a public HTTPS URL.
External Images
Pandoc can fetch images from HTTPS URLs when the --embed-resources flag is passed. The fetched image is embedded in the output document. This requires network access during the conversion.
Hyperlinks
With Pandoc and LaTeX (colorlinks: true in frontmatter), hyperlinks render as colored clickable text in the PDF viewer. For print output, the @media print rule shown above appends the URL in parentheses after each link’s anchor text, making the destination visible on paper.
For more on Markdown syntax, see the Markdown cheat sheet. To inspect your Markdown before converting, use the SnapUtils Markdown Previewer.
Preview Markdown with GitHub-Flavored Rendering
The SnapUtils Markdown Previewer renders tables, task lists, strikethrough, fenced code blocks, and all GitHub-flavored Markdown extensions. Verify your document looks right before converting to PDF.
Open Markdown Previewer Free9. Frequently Asked Questions
How do I convert Markdown to PDF?
The fastest no-install method: open the SnapUtils Markdown Previewer, paste your Markdown, and use your browser’s Print dialog (Ctrl+P or Cmd+P) with “Save as PDF” as the destination. For command-line conversion, install Pandoc and run pandoc input.md -o output.pdf. For VS Code users, install the “Markdown PDF” extension by yzane and right-click in the editor to select “Markdown PDF: Export (pdf)”.
Does Pandoc preserve code block syntax highlighting in PDF?
Yes. Pandoc applies syntax highlighting to fenced code blocks that include a language identifier. When converting to PDF via LaTeX, highlighting is handled by the listings package. Use the --highlight-style flag to choose a color theme: pygments, tango, espresso, zenburn, and others. When converting via an HTML-based engine, highlighting is applied through CSS classes in the intermediate HTML.
Can I use custom fonts in a Markdown-to-PDF conversion?
Yes. With Pandoc and a LaTeX engine, specify fonts in the YAML frontmatter: mainfont: Georgia, monofont: JetBrains Mono. Use --pdf-engine=xelatex for full Unicode and system font support. With CSS-based conversion (browser print or VS Code extension), add a @font-face declaration or Google Fonts link in your stylesheet and reference the font in the font-family property.
What is the best tool to convert Markdown to PDF?
For technical documents with code blocks and precise typesetting: Pandoc with XeLaTeX produces the highest quality output. For quick sharing without any installation: browser print-to-PDF from the SnapUtils Markdown Previewer. For VS Code developers: the Markdown PDF extension is the most frictionless workflow. For automated pipelines: Pandoc with a shell script or a headless Chrome instance via Puppeteer are the most reliable and scriptable options.