Use Cases August 5, 2026

Markdown to PDF: 5 Ways That Actually Preserve Formatting

You write in Markdown for clarity.

Markdown to PDF: 5 Ways That Actually Preserve Formatting
ForgeMD Markdown Use Cases

You write in Markdown for clarity. You ship PDFs for polish. Somewhere between hitting save and sending the file, the formatting ghosts you.

Tables break. Code blocks overflow. The font you picked in CSS lands as Times New Roman 12. This is the quiet crisis of “convert Markdown to PDF”: a dozen tools promise it, almost none tell you why the output looks wrong or what to do when it does.

Here are the five real approaches that actually render correctly, ranked by reliability, and the one that fits your day.

The problem is not the format, it is the rendering engine

Markdown, by design, leaves styling to the consumer. A .md file is structure: headings, lists, code blocks, links. It says nothing about margins, fonts, or page breaks. The PDF you get depends entirely on what tool sits between your .md file and the .pdf file. Pick the wrong one and the output looks wrong, even if the Markdown is perfectly valid.

The five methods below differ in exactly one thing: how much control you get over that rendering step.

MethodRendering engineFormatting controlBest for
Browser print to PDFChromium / WebKitLowQuick one-offs
VS Code export to PDFMarkdown-It + print CSSMediumDevs in VS Code
PandocHTML/CSS template engineHighCustom styling
TypstNative typesettingVery highAcademic / print polish
ForgeMD exportTipTap + print CSSMedium-HighCollaborative docs

Method 1: Browser print to PDF (Chrome / Firefox)

This is what you get when you open a Markdown preview in VS Code (with the built-in preview extension), Obsidian, or GitHub and press Ctrl+P.

  • Pro: Zero setup. Works in every browser.
  • Con: Your CSS does not carry over. Tables run off the page. Margins are fixed.
  • When to use: A single document, one time, no custom styling needed.

Tip: VS Code’s built-in preview lets you inject custom CSS before printing, a quick fix for margin issues, but nothing that survives version updates.

Method 2: VS Code export to PDF

If Markdown is your daily environment, VS Code’s export path is the least friction.

  • Pro: Uses your preview theme. Supports custom CSS via the extension settings.
  • Con: No page-break controls. Code blocks and images can split across pages unpredictably.
  • When to use: You live in VS Code and just need something clean enough for internal review.

Setup: Install “Markdown PDF” extension. In settings, point markdownpdf.styles to your custom CSS file. Export via the command palette.

Method 3: Pandoc (the power tool)

Pandoc is the Unix pipe for document conversion. It reads Markdown and can output PDF through LaTeX, HTML/CSS, or directly via WeasyPrint.

  • Pro: Template system. Custom fonts, headers, footers, page numbers, cover pages. Supports every Markdown flavor.
  • Con: Installation is a rite of passage. LaTeX setup alone can eat an afternoon. Debugging broken templates feels like archaeology.
  • When to use: You need production-quality PDFs (reports, proposals, academic papers) and have the patience to set it up once.

Copy-paste recipe:

# HTML/CSS path (simplest)
pandoc input.md -o output.pdf \
  --css=custom.css \
  --pdf-engine=weasyprint

# LaTeX path (most control)
pandoc input.md -o output.pdf \
  -V geometry:margin=1in \
  -V fontsize:11pt \
  -V mainfont="Inter" \
  --toc

ForgeMD includes an optional Pandoc integration for extended import/export formats beyond its native Markdown, PDF, HTML, DOCX, LaTeX, Epub, and ODT. This is the path if you need Word-perfect round-trips.

Method 4: Typst (the new alternative)

Typst is a typesetting system that feels like Markdown but compiles to PDF-quality output directly.

  • Pro: Built-in page breaks, columns, bibliographies. Looks expensive by default. Written in Rust (fast).
  • Con: Syntax is Markdown-like but not Markdown, you relearn lists and headings. No WYSIWYG.
  • When to use: Academic papers, CVs, reports where typography matters more than familiarity.

Quick start:

typst compile paper.typ paper.pdf

Method 5: ForgeMD export (collaborative docs)

If your document lives in ForgeMD, export is a single click. File → Export → PDF.

  • Pro: Preserves the WYSIWYG/Markdown split-screen styling. Exports tables, code blocks, Mermaid diagrams, and inline charts. Works fully offline via the desktop app.
  • Con: Less fine-grained control than Pandoc templates.
  • When to use: The doc you are exporting is actively being co-edited, or you need it exported from a locked-down laptop with no LaTeX installed.

The export uses TipTap’s rendering engine with print-optimized CSS, so what you see in the editor is what the PDF looks like, including custom font sizes, dark/light mode, and image dimensions you set in the editor.

Formatting survival guide

These problems show up in every method. Here is how to fix them.

Tables that split across pages

Most converters break tables at page boundaries. Fix: add page-break-inside: avoid; to your table CSS, or keep tables under 20 rows.

Code blocks that overflow

Solution: set pre { overflow-x: auto; white-space: pre-wrap; } in your print CSS. Long lines wrap instead of disappearing.

Images that scale wrong

Always specify image dimensions in the Markdown: ![alt](image.png){width=500px}. Pandoc passes these through; browser print usually ignores them.

Page numbers and headers

Pandoc: use -V header-left="My Report" and -V include-running-counters. Typst: built-in. ForgeMD: export includes filename + timestamp; for headers, use the Pro plan’s document templates.

FAQ

Which method preserves my custom CSS?

Pandoc (with --css) and Typst give the most control. ForgeMD’s export uses print-optimized CSS but does not accept custom stylesheets yet.

Can I automate Markdown to PDF conversion?

Yes, both Pandoc and Typst run from the command line, so you can wire them into CI/CD pipelines or GitHub Actions. ForgeMD’s REST API also supports programmatic export for Pro and Team plan users.

Is the browser print method good enough?

For quick internal docs, yes. For anything shared externally, use Pandoc or Typst.

Does ForgeMD export to PPT?

No. ForgeMD exports to Markdown, PDF, HTML, DOCX, LaTeX, Epub, and ODT (with extended formats via Pandoc integration). PowerPoint is not in the current export list.

Get started

Create Markdown Documents Without Compromise

Free 5-day trial · Works fully offline · Cancel anytime