@joaodotwork/md-2-pdf
v1.2.0
Published
Convert markdown files to PDF with mermaid diagram support
Maintainers
Readme
md-2-pdf
A powerful CLI tool to convert Markdown files to PDF with built-in Mermaid diagram support. It bridges the gap between GitHub-flavored documentation and professional PDF exports.
Why md-2-pdf?
Most markdown-to-pdf converters struggle with diagrams or produce poorly formatted documents. md-2-pdf is designed to:
- Preserve Vector Quality: Renders Mermaid diagrams as PDF vectors (not bitmaps) for lossless scaling.
- Support GFM Conventions: Handles lists interrupting paragraphs, task lists, and other GitHub Flavored Markdown features.
- Professional Typography: Uses
xelatexby default for high-quality typesetting with smart page breaking.
Key Features
- Mermaid Diagrams: Automatically detects ````mermaid` blocks and renders them as vector graphics.
- Smart Formatting:
- Standardized 11pt font and optimized line spacing.
- Interactive, blue clickable links.
- Automatic widow/orphan protection (keeps headers with content).
- Customizable margins and geometry.
- Multi-Engine Support: Automatically detects and uses the best available PDF engine (
xelatex,pdflatex,weasyprint, orwkhtmltopdf). - Batch Processing: Convert single files or entire directories with one command.
Installation
Prerequisites
- Node.js & npm (Required for Mermaid rendering)
- Python 3 (Required for the core logic)
- Pandoc (The engine behind the conversion)
- PDF Engine (One of the following):
- Recommended:
xelatex(Install via MacTeX on macOS ortexlive-fullon Linux) - Alternative:
weasyprint(pip install weasyprint)
- Recommended:
Install via npm
npm install -g @joaodotwork/md-2-pdfOr use pnpm / yarn:
pnpm add -g @joaodotwork/md-2-pdfUsage
Single File Conversion
md-2-pdf manual.mdCreates manual.pdf in the same directory.
Batch Processing
Convert all markdown files in a directory:
md-2-pdf ./documentationAdvanced Options
# Specify a custom output name
md-2-pdf proposal.md -o Final_Proposal.pdf
# Check if all dependencies are correctly installed
md-2-pdf --check-onlyMermaid Support
Simply use standard Mermaid syntax in your markdown:
graph TD;
A[Markdown File] -->|Processor| B(Extract Mermaid);
B --> C{Render to PDF};
C -->|Vector| D[High-Quality PDF];The tool will extract these blocks, render them using mermaid-cli, and embed them back into the final document seamlessly.
Troubleshooting
If you encounter issues with PDF generation, ensure pandoc and a LaTeX engine (like xelatex) are in your PATH. You can verify this by running:
md-2-pdf --check-onlyLicense
MIT © Joao Doria de Souza
