Convert Markdown to PDF with Mermaid diagrams, KaTeX math, Obsidian syntax, syntax highlighting, batch processing, and Table of Contents generation. Available as a CLI and Node.js API.
md2pdf is a Markdown-to-PDF rendering engine built on the Unified ecosystem (Remark/Rehype) and Playwright. It generates PDFs with correct pagination, margins, and typography using headless Chromium.
For detailed release notes, visit the GitHub Releases page.
- Batch Processing: Convert multiple files concurrently (
md2pdf *.md). Uses a persistent Chromium instance for faster processing. - Incremental Cache: Caches output to speed up batch conversions. Skips unchanged files automatically. Control caching with
--no-cacheand--clear-cache. - Plugin API: Extend functionality using
MarkdownPlugin,HtmlPlugin,RenderPlugin,ThemePlugin, andExportPlugin. See the Plugin Documentation. - Theming: Includes 7 built-in themes (
default,github,obsidian-light,obsidian-dark,dracula,nord,academic). Use--theme <name>to apply. - Obsidian Parity: Supports native callouts, wiki-links (
[[Link]]), tags, embeds (![[Image.png]]), highlights (==highlight==), and YAML frontmatter. - Syntax Highlighting: Uses Shiki for syntax highlighting across 20+ languages.
- Mermaid Diagrams: Native diagram rendering from code blocks. Safe for concurrent multi-file processing.
- Math Rendering: Supports KaTeX for inline and display LaTeX equations.
- Configuration: Supports persistent configuration files (
md2pdf.config.ts,json,yaml) and profiles. See the Configuration Guide. - Diagnostics: Use
md2pdf doctorandmd2pdf initfor environment setup and troubleshooting.
# Install globally
npm install -g @amitdevx/md2pdf
md2pdf init
# Or use locally within a project
npm install @amitdevx/md2pdf
npx md2pdf initNote: Due to npm v12
allowScriptsdefaults, browser binaries are not downloaded automatically during install. You must runmd2pdf initafter installation to fetch the required Chromium dependencies.
Generate a PDF from a single Markdown file:
md2pdf README.mdProcess multiple files at once using wildcards:
md2pdf "docs/*.md" --output out_dir/Specify a custom output path and generate a Table of Contents:
md2pdf input.md --output custom.pdf --tocConvert with custom paper size and margins:
md2pdf input.md --paper Letter --margin 15mmForce a page break before every H1 heading:
md2pdf input.md --h1-new-pageInitialize a new environment and download dependencies:
md2pdf initCheck system health and pipeline status:
md2pdf doctorPrint advanced internal variables and stack traces if an error occurs:
md2pdf input.md --debugEmbed the rendering engine in your Node.js applications:
import { convert } from '@amitdevx/md2pdf';
const result = await convert({
input: 'README.md',
output: 'README.pdf',
paper: 'A4',
margin: '20mm',
toc: true
});
console.log(`Render time: ${result.renderTimeMs}ms`);git clone https://github.com/amitdevx/md2pdf.git
cd md2pdf
npm install
npx md2pdf initPlease refer to docs/contributing.md for our guidelines, branch naming conventions, and coding standards.
MIT License. See LICENSE for details.
Amit Divekar | amitdevx.tech | Project Page | GitHub