@amitdevx/md2pdf
Production-grade open-source Markdown to PDF rendering engine for Node.js that converts Markdown into high-fidelity PDFs using Playwright, Chromium, and the Unified processing pipeline.
Installation
# Install globally
npm install -g @amitdevx/md2pdf
md2pdf init
# Or use locally within a project
npm install @amitdevx/md2pdf
npx md2pdf init
Practical Use Cases
README.md ➔ README.pdf
import { convert } from "@amitdevx/md2pdf";
const result = await convert({input: "./README.md", output: "./README.pdf",});Automated Release Notes
# GitHub Actions automated generation
md2pdf CHANGELOG.md --output release.pdfTechnical Documentation
md2pdf docs/architecture.md \--output build/architecture.pdf \--toc \--paper A4Resume Generation
md2pdf resume.md \--output resume.pdf \--margin 15mmRendering Pipeline
Key Features
- Native KaTeX Offline Math (mhchem)
- Mermaid & Architecture Diagrams
- Obsidian callouts, wiki-links, tags, embeds, highlights
- Batch processing with single Chromium instance
- Config file support (md2pdf.config.ts/json/yaml)
- md2pdf doctor & init diagnostic tooling
- GFM tables, strikethrough, task lists, footnotes
- Table of Contents with depth control
- Custom headers/footers with dynamic page numbers
- --json-errors & Structured error codes for CI
- JavaScript & TypeScript API
- Professional Typography & Syntax highlighting (Shiki)
CLI Usage
Quick and powerful commands to generate PDFs directly from your terminal.
# Generate a PDF from a single Markdown file:
md2pdf README.md
# Specify a custom output path and generate a Table of Contents:
md2pdf input.md --output custom.pdf --toc
# Convert with custom paper size and margins:
md2pdf input.md --paper Letter --margin 15mm
# Force a page break before every H1 heading:
md2pdf input.md --h1-new-page
# Batch mode:
md2pdf "docs/*.md" --output out_dir/
# With config file:
md2pdf input.md --config md2pdf.config.json
# Obsidian vault:
md2pdf note.md --vault-root ./vault --resolve-links
# Machine-readable errors (CI):
md2pdf input.md --json-errors
# Verbose output:
md2pdf input.md --verbose
Rendered Output
Side-by-side comparison showcasing typography, syntax highlighting, and layout accuracy.
The **md2pdf** engine supports native mathematics & diagrams.
```mermaid
graph TD
AST --> Playwright
```
## Equation
$$
E = mc^2
$$
System Architecture
The md2pdf engine supports native mathematics & diagrams.
Equation
Diagnostics & Setup
Built-in tools to ensure your rendering environment is perfectly configured.
# Initialize a new environment and download dependencies automatically:
md2pdf init
# Check your system health and Playwright pipeline status:
md2pdf doctor
# Print advanced internal variables and stack traces if an error occurs:
md2pdf input.md --debug
Library Usage
Embed the rendering engine directly 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`);
| Option | Type | Description |
|---|---|---|
| math | boolean | Enable KaTeX/mhchem rendering |
| theme | string | Custom CSS theme path |
| mermaid.theme | string | default, dark, forest, neutral |
| pageBreaks | boolean | Force page breaks on headers |
| metadata | object | PDF Author, Title, Keywords |
| header / footer | string | Custom HTML templates |
Release Timeline
Engineering Focus
The project demonstrates building and maintaining a production-quality open-source developer tool with emphasis on: