Pixel-perfect Markdown → PDF.
Preview it in your browser, paginate in A4, then export exactly what you see.
Stop guessing how your PDF will look.
md2pdf opens a real paginated preview, lets you pick a template and font, and generates a WYSIWYG PDF with identical layout.
The missing WYSIWYG Markdown → PDF CLI.
Most Markdown → PDF tools:
- render differently in the final PDF
- break pagination
- require complex Pandoc configs
- don't support Mermaid/KaTeX properly
- have no visual template selection
md2pdf fixes that.
👉 What you preview = what you export.
- 🖥️ Browser-based A4 preview with real pagination
- 👀 Live watch reload — edit your
.mdin any editor, preview refreshes automatically (scroll position preserved) - 🎨 7 templates — Clean · Classic · Modern · Academic · Editorial · Manuscript · Technical
- 🔤 8 fonts — Fraunces · Instrument Serif · EB Garamond · Jakarta Sans · Figtree · Times · JetBrains Mono · Template Default
- 📐 Adjustable margins — vertical/horizontal, 5–30 mm
- 🧭 Document outline drawer with click-to-jump headings
- 🔍 Page navigator + zoom (Fit · 50 · 75 · 100 · 125 · 150 %)
- 📊 Word count + reading time
- 🌀 Terminal spinner during PDF conversion
- 📐 KaTeX math support
- 🧩 Mermaid diagrams
- ☑️ Task lists
- 🖼️ Relative image auto-resolution
- 🛡️ Overwrite protection
md2pdf file.mdPreview → choose style → export → done.
- Node.js 20+
- Chromium-based browser (Chrome, Chromium, Edge, or Brave)
On macOS, default browser paths are scanned automatically. If your browser is in a different location, set the
CHROME_PATHenvironment variable.
npm install -g github:merttcetn/md2pdfThis command installs dependencies, builds the project, and makes the md2pdf command available globally.
git clone https://github.com/merttcetn/md2pdf.git
cd md2pdf
npm install # installs dependencies and builds automatically
npm install -g .bash installation.shIf you do not want a global installation:
bash installation.sh --no-globalnpm update -g md2pdfcd md2pdf
git pull
npm install
npm install -g .md2pdf file.md- A preview opens in your browser.
- Select a template and font.
- Set the output PDF path.
- Click OK to generate the PDF, or Cancel to exit.
npm install # install dependencies + build
npm run build # manual build
npm test # run testssrc/
cli.ts # Express + SSE server + CLI entry point
main/
pdf-service.ts # PDF generation with Playwright (+ margin support)
path-utils.ts # File path utilities
file-watcher.ts # Debounced fs.watch for live reload
spinner.ts # Terminal Braille spinner
renderer/
index.html # Web UI (editorial layout)
renderer.ts # Markdown render + pagination + UI wiring
styles.css # Editorial theme (cream paper, Fraunces)
watch-client.ts # SSE EventSource + scroll preservation
outline.ts # Document outline DOM helpers
page-navigator.ts # Page nav + zoom controls
word-count.ts # Word count + reading time (re-export)
shared/
types.ts # Shared type definitions
templates.ts # Template list
outline-extract.ts # Pure heading extractor
word-count-stats.ts # Pure stats computation
tests/
*.test.ts # node:test unit tests