How to Convert Markdown to PDF

Three practical methods to turn Markdown documents into PDF files — browser tools, command-line, and editors.

5 min read

You wrote your document in Markdown. Now someone needs it as a PDF. Maybe it's a report for a client, a proposal you're emailing, or documentation you want to share with people who don't have a Markdown viewer. Whatever the reason, you need a reliable way to go from .md to .pdf.

There are three good approaches, each with different tradeoffs. Pick the one that fits your workflow.

Method 1: Use an Online Converter

The fastest option when you just need a quick PDF. No installation, no configuration. Open the tool, paste your Markdown, download the PDF.

MDConvert's Markdown to PDF tool runs entirely in your browser — your content never leaves your machine. Paste or type your Markdown on the left, see the rendered preview on the right, and hit the download button when it looks right.

This works well for:

  • Quick one-off conversions
  • Documents without complex custom styling
  • Situations where you don't want to install anything
  • Working from a machine that isn't your main dev environment

The main limitation is styling control. You get clean, readable defaults, but if you need specific fonts, custom headers/footers, or brand-specific layouts, you'll want one of the other methods.

Method 2: VS Code Extensions

If you already live in VS Code, this keeps everything in one place. There are several extensions that add PDF export to your editor.

Markdown PDF

The most popular option. Install the "Markdown PDF" extension by yzane, open your .md file, and run the "Markdown PDF: Export (pdf)" command from the command palette (Ctrl+Shift+P / Cmd+Shift+P).

It uses Chromium under the hood, so the output looks like what you'd see in a browser. You can customize:

  • Page size and margins via extension settings
  • Custom CSS by pointing to a stylesheet
  • Headers and footers with page numbers

Markdown Preview Enhanced

Another solid choice. This extension gives you a richer preview with support for diagrams (Mermaid, PlantUML), LaTeX math, and more. It can export to PDF through either Chromium (Puppeteer) or Prince. The setup is slightly more involved, but you get more output options.

The VS Code approach is good when you're editing and exporting frequently during a writing session. You tweak the Markdown, preview it, and export without switching contexts.

Method 3: Command Line with Pandoc

Pandoc is the Swiss army knife of document conversion. If you need to automate PDF generation, handle complex documents, or have precise control over output, this is the way.

Install Pandoc and a LaTeX distribution (for PDF output):

# macOS
brew install pandoc
brew install --cask mactex-no-gui

# Ubuntu / Debian
sudo apt install pandoc texlive-latex-recommended

# Windows (with Chocolatey)
choco install pandoc miktex

Then convert:

pandoc input.md -o output.pdf

That's the simplest version. For more control:

pandoc input.md \
  -o output.pdf \
  --pdf-engine=xelatex \
  -V geometry:margin=1in \
  -V fontsize=11pt \
  -V mainfont="Inter" \
  --highlight-style=tango \
  --toc

This sets margins, font size, a specific typeface, syntax highlighting style, and auto-generates a table of contents from your headings.

Pandoc is the right choice when:

  • You need to batch-convert multiple files
  • The document includes LaTeX math, citations, or cross-references
  • You want to automate conversions in CI/CD pipelines
  • You need fine-grained typographic control

The tradeoff is setup complexity. Installing LaTeX is a large download (several GB), and debugging LaTeX errors can be frustrating if you're not familiar with it. For simpler documents, it's overkill.

Choosing the Right Method

CriteriaOnline ConverterVS Code ExtensionPandoc CLI
Setup requiredNoneInstall extensionInstall Pandoc + LaTeX
SpeedInstantFastFast (after install)
Custom stylingLimitedModerate (CSS)Full control
Batch conversionNoNoYes
Offline useDependsYesYes
Best forQuick one-offsRegular writingAutomation & complex docs

Styling Tips

Regardless of which method you pick, a few things make your PDFs look better:

  • Use heading hierarchy properly. Start with one H1, use H2 for sections, H3 for subsections. This gives the PDF a clear visual structure and makes auto-generated tables of contents work correctly.
  • Add page breaks where they matter. In Pandoc, use \newpage or \pagebreak. In HTML-based converters, use CSS: page-break-before: always.
  • Keep code blocks short. Long code blocks can overflow the page in PDF. If a block is more than 30-40 lines, consider splitting it or reducing the font size.
  • Test with real content. Don't wait until the final draft to try the conversion. Run it early so you can catch layout issues while you still have time to adjust.
  • Check images. Make sure images are high enough resolution for print (if applicable) and that their paths resolve correctly during conversion.

The best method is the one that matches how you already work. If you're converting one document right now, use the online tool. If you do this daily, set up VS Code or Pandoc once and forget about it.