Tutorial

Export Markdown to PDF in VS Code (Step by Step)

June 24, 2026 · 5 min read

If you write documentation, READMEs, or notes in VS Code, you can turn any .md file into a polished PDF without leaving the editor. The most popular way is the Markdown PDF extension by yzane, which renders your file through a headless Chromium instance so tables, code highlighting, and math all come out looking exactly like they do in the preview.

This guide walks through installing the extension, exporting your first PDF, and customizing page size, margins, headers, and styles. If you don't use VS Code or want zero setup, skip to the no-install alternative at the end.

Install the Markdown PDF extension

  1. Open the Extensions panel with Ctrl+Shift+X (Cmd+Shift+X on macOS).
  2. Search for Markdown PDF.
  3. Pick the one published by yzane (extension id yzane.markdown-pdf) and click Install.

That's it. There's no account, no license key, and nothing to configure to get a working export.

Export a Markdown file to PDF

Open the .md file you want to convert, then:

  1. Open the Command Palette with Ctrl+Shift+P (Cmd+Shift+P on macOS).
  2. Type Markdown PDF and choose Markdown PDF: Export (pdf).
  3. The PDF is written next to your source file with the same name.

The extension can also export to other formats from the same menu: Export (html), Export (png), and Export (jpeg). There's an Export (all) command too if you want every format at once. You can also right-click inside the editor and pick the export commands from the context menu.

How rendering works

Under the hood, the extension launches a headless Chromium browser, loads your rendered Markdown as HTML, and prints it to PDF. Because it uses a real browser engine, the output matches what you see in VS Code's built-in preview: GitHub-flavored tables keep their borders and alignment, fenced code blocks stay syntax-highlighted, and images resolve correctly. It also supports Mermaid diagrams and KaTeX math, so this renders as an actual diagram and equation rather than raw text:

```mermaid
graph LR
  A[Write Markdown] --> B[Export PDF]
```

Inline math like $E = mc^2$ and block math both render via KaTeX.

Customize the output in settings.json

All customization lives in your VS Code settings. Open the Command Palette and run Preferences: Open User Settings (JSON), then add the keys you need. Here is a practical configuration for A4 documentation with page numbers and a custom stylesheet:

{
  "markdown-pdf.format": "A4",
  "markdown-pdf.margin.top": "1.5cm",
  "markdown-pdf.margin.bottom": "1.5cm",
  "markdown-pdf.margin.left": "2cm",
  "markdown-pdf.margin.right": "2cm",
  "markdown-pdf.styles": ["./pdf-style.css"],
  "markdown-pdf.highlightStyle": "github",
  "markdown-pdf.displayHeaderFooter": true,
  "markdown-pdf.headerTemplate": "<div style=\"font-size:9px; width:100%; text-align:center;\"><span class=\"title\"></span></div>",
  "markdown-pdf.footerTemplate": "<div style=\"font-size:9px; width:100%; text-align:center;\">Page <span class=\"pageNumber\"></span> of <span class=\"totalPages\"></span></div>"
}

What each setting does:

Your pdf-style.css can be as simple as:

body {
  font-family: -apple-system, "Segoe UI", sans-serif;
  line-height: 1.6;
}
h1, h2 {
  border-bottom: 1px solid #ddd;
  padding-bottom: 0.2em;
}

Troubleshooting

{
  "markdown-pdf.executablePath": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
}

On Windows this is typically C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe, and on Linux something like /usr/bin/google-chrome. Reload the window after changing it.

No-install alternative: convert in your browser

The VS Code extension is great if you already live in the editor, but it isn't the only option. If you're on a machine where you can't install extensions, you're helping a non-developer, or you just want a clean PDF without touching settings, use a browser-based converter instead.

ConvertMDapp is a free Markdown-to-PDF tool that runs 100% in your browser — your files never leave your device, so it's genuinely private with no upload step. There's no signup and no watermark. You get a live two-way preview, syntax-highlighted code blocks, editable tables, and a light/dark theme, then you export a clean PDF (or download the .md) in one click. It's the fastest path when setup and privacy matter more than editor integration. Open the converter and paste your Markdown to try it.

For deeper background on other approaches, see the pillar guide on how to convert Markdown to PDF, and if you prefer a command-line workflow with fine-grained control, read about using Pandoc for Markdown to PDF.

FAQ

Does the Markdown PDF extension require an internet connection? Only for the first export, when it downloads Chromium. After that it works offline. If you can't download Chromium (for example, behind a proxy), set markdown-pdf.executablePath to a local Chrome install and you're set.

Why do my code blocks or tables look wrong in the PDF? Both are rendered by Chromium, so they should match the VS Code preview. If code isn't highlighted, check markdown-pdf.highlightStyle; if tables look off, make sure you're using valid GitHub-flavored Markdown table syntax. A custom markdown-pdf.styles sheet can also override spacing and fonts.

Can I convert Markdown to PDF without installing anything? Yes. Use the browser-based ConvertMDapp converter — it's free, needs no signup or install, keeps your files on your device, and exports a clean, watermark-free PDF in one click.