md-to-pdf-cli
May 30, 2026
md
pdf
cli
python
chromium
PyPI
GitHub Repository
Project Overview
md-to-pdf-cli is a command-line tool that converts local Markdown files into high-quality PDF documents using headless Chromium. It is built with CJK (Chinese, Japanese, Korean) character support as a first-class concern, and handles mathematical equations, diagrams, and syntax-highlighted code blocks out of the box — fully offline.
Key Features
- CJK Support: UTF-8 rendering with CJK-first font stacking for proper display of Chinese, Japanese, and Korean characters.
- Code Highlighting: Server-side syntax highlighting via Pygments with multiple color schemes.
- Mathematics: LaTeX equation rendering using KaTeX for both inline (
$...$) and block ($$...$$) expressions. - Diagrams: Mermaid diagram rendering for flowcharts, sequence diagrams, and other visualizations.
- Table of Contents: Auto-generated TOC with PDF bookmarks derived from the heading structure.
- Table Support: GitHub Flavored Markdown tables with proper pagination and repeated headers across pages.
- Headers / Footers: Customizable page headers and footers with template placeholders.
- Image Handling: Supports both relative and remote images, with optional embedding.
- Offline Processing: All assets are inlined for reproducible, air-gapped conversion.
Usage
md2pdf report.md # generates report.pdf
md2pdf report.md -o out/doc.pdf # custom output path
Configuration is auto-loaded from md2pdf.toml in the current directory. Supported options include page size, margins, orientation, CSS theming, code highlight style, math / Mermaid rendering toggles, and footer templates. see more README
Technology Stack
- Language: Python 3.12+
- PDF Engine: Headless Chromium via Playwright
- Syntax Highlighting: Pygments
- Math Rendering: KaTeX
- Diagram Rendering: Mermaid
- Markdown Parsing: Python-Markdown with GFM extensions
- Distribution: PyPI (
pip install md-to-pdf-cli)
License
MIT