md2pdf-context
v1.0.2
Published
Convert Markdown to PDF with one right-click. Supports Mermaid, syntax highlighting, math, themes and more.
Maintainers
Readme
md2pdf-context
Convert Markdown to PDF with a single right-click. Supports Mermaid diagrams, syntax highlighting, math (KaTeX), themes, batch conversion and more.
Features
- Right-click → Convert to PDF on any
.mdfile (Windows & Linux) - Mermaid diagrams rendered as SVG
- Syntax highlighting via highlight.js
- Math / LaTeX via KaTeX (
$inline$and$$block$$) - Task lists with checkboxes
- YAML Frontmatter support
- Table of Contents generation
- 3 built-in themes:
github,dark,minimal - Custom CSS themes
- Batch conversion — entire folders at once
- CLI (
md2pdf) for scripting and automation - Standalone
.exe— no Node.js required for end users
Installation
Option 1 — Right-click installer (Windows)
Requires Node.js (LTS)
- Download and extract the zip
- Right-click
scripts/install-windows.bat→ Run as Administrator - Done — right-click any
.mdfile and choose "Convert to PDF"
Option 2 — Global CLI via npm
npm install -g md2pdf-context
md2pdf yourfile.mdOption 3 — Standalone .exe (no Node.js needed)
Download the latest .exe from the Releases page.
md2pdf.exe yourfile.md
md2pdf.exe myfolder/Linux / macOS
git clone https://github.com/RedFeatherXO/md2pdf-context.git
cd md2pdf-context
bash scripts/install-unix.shUsage
CLI
# Single file
md2pdf README.md
# Batch — whole folder
md2pdf docs/
# Multiple files
md2pdf file1.md file2.md file3.md
# Custom theme
md2pdf file.md --theme dark
# With Table of Contents
md2pdf file.md --toc
# Landscape A3
md2pdf file.md --format A3 --landscape
# Custom output path
md2pdf file.md -o output/report.pdf
# All options
md2pdf --helpAll CLI Options
| Option | Default | Description |
| ---------------------- | -------- | ----------------------------------------------------- |
| --theme <name> | github | Theme: github, dark, minimal, or path to .css |
| --format <fmt> | A4 | Page format: A4, A3, Letter, Legal |
| --landscape | false | Landscape orientation |
| --toc | false | Generate Table of Contents |
| --toc-depth <n> | 3 | TOC heading depth (1–6) |
| --no-mermaid | — | Disable Mermaid rendering |
| --no-highlight | — | Disable syntax highlighting |
| --no-math | — | Disable KaTeX math |
| --margin-top <mm> | 20mm | Top margin |
| --margin-bottom <mm> | 20mm | Bottom margin |
| --margin-left <mm> | 20mm | Left margin |
| --margin-right <mm> | 20mm | Right margin |
| -o, --output <path> | — | Output file path |
Configuration
Place a md2pdf.config.json in your project folder (or any parent folder):
{
"theme": "github",
"format": "A4",
"landscape": false,
"margins": {
"top": "20mm",
"right": "20mm",
"bottom": "20mm",
"left": "20mm"
},
"mermaid": true,
"highlight": true,
"math": true,
"toc": false,
"tocDepth": 3
}Config files are discovered by walking up the directory tree from the input file.
YAML Frontmatter
You can also configure per-file in the Markdown itself:
---
title: My Document
theme: dark
format: A3
landscape: true
toc: true
---
# My Document
...Themes
| Theme | Description |
| --------- | --------------------------- |
| github | GitHub-style (default) |
| dark | Dark mode (GitHub Dark) |
| minimal | Clean serif, print-friendly |
Custom Theme
Point to any .css file:
md2pdf file.md --theme ./my-custom-theme.cssOr in config:
{ "theme": "./themes/corporate.css" }Mermaid Example
```mermaid
graph TD
A[Start] --> B{Decision}
B -->|Yes| C[Do it]
B -->|No| D[Skip]
```Math Example
Inline: $E = mc^2$
Block:
$$
\int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2}
$$Task List Example
- [x] Install md2pdf-context
- [x] Convert first file
- [ ] Publish to GitHubBuilding the .exe
Requires pkg:
npm install
npm run build:exe
# Output: dist/md2pdf-win.exe, dist/md2pdf-linux, dist/md2pdf-macosRequirements
- Node.js >= 16 (not needed for
.exe) - Internet connection during conversion (CDN: Mermaid, highlight.js, KaTeX)
- Note: Currently, this tool has primarily been tested on Windows 10. Linux and macOS versions are provided but should be considered experimental.
Offline mode: Download the CDN assets and point to local files in a custom theme — see wiki.
License
MIT — do whatever you want with it.
