@joaodotwork/md-2-pdf
v1.1.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 automatically handles:
- Mermaid Diagrams: Renders
mermaidcode blocks into high-quality vector graphics (PDF) for lossless scaling. - PDF Generation: Uses
xelatex(orweasyprint/wkhtmltopdfas fallbacks) for professional PDF output. - Smart Formatting: Includes improved defaults for readability (margins, fonts, links) and prevents bad page breaks (widows/orphans).
Installation
Prerequisites
- Node.js & npm (Installed automatically with the package)
- Python 3 (Required for the core script)
- PDF Engine (One of the following):
- Recommended:
xelatex(Install via MacTeX on macOS ortexliveon Linux) - Fallback:
weasyprint(pip install weasyprint)
- Recommended:
Install via npm
npm install -g @joaodotwork/md-2-pdfUsage
Convert a File
md-2-pdf input.mdThis creates input.pdf in the same directory.
Convert a Directory
Process all .md files in a folder:
md-2-pdf ./docsOptions
# Specify output location
md-2-pdf input.md -o output.pdf
# Check dependencies
md-2-pdf --check-onlyFeatures
Mermaid Support:
graph TD; A-->B; A-->C; B-->D; C-->D;Just use standard ````mermaid blocks in your markdown. Now renders as vector graphics (PDF) instead of bitmaps for perfect clarity in your PDF exports.
Clean Layout:
- Standardized font size (11pt) and line spacing (1.2).
- Blue clickable links.
- Horizontal rules (
---) rendered as vertical space instead of lines. - Smart page breaking rules to keep headers with content.
License
ISC
