md2pdf-mermaid-video-light.mp4
Watch md2pdf-mermaid in action!
Professional Markdown to PDF converter with emoji support and automatic Mermaid diagram rendering
Convert your Markdown documentation to beautiful PDFs with:
- β Full emoji support π (colored, native rendering)
- β Automatic Mermaid diagram rendering (high-quality PNG images)
- β
Table of contents generation (with
[TOC]marker) - β Page numbering (automatic footer pagination)
- β Professional formatting (headers, tables, code blocks)
- β Multiple page sizes (A4, A3, Letter)
- β Portrait & Landscape orientation support
- β Full Unicode/UTF-8 support (multilingual text, special characters)
- β Syntax highlighting for code blocks
- β CLI and Python API
- β Fast and reliable
# From PyPI (recommended)
pip install md2pdf-mermaid
# Install Playwright browser (required for rendering)
playwright install chromiumAlternative - From Git repository:
pip install git+https://github.com/rbutinar/md2pdf-mermaid.git
playwright install chromiummacOS Users: Use a virtual environment (required for externally-managed Python):
python3 -m venv venv
source venv/bin/activate
pip install md2pdf-mermaid
playwright install chromiumSee MACOS_SETUP.md for detailed instructions.
WSL Users: Use Windows Python to avoid dependency issues:
python3.exe -m venv venv # Windows venv, no sudo needed!
venv/Scripts/pip.exe install md2pdf-mermaid
venv/Scripts/playwright.exe install chromiumSee WSL_SETUP.md for details.
# Basic conversion (emoji and Mermaid just work!)
md2pdf document.md
# Custom output name
md2pdf document.md -o report.pdf
# Custom title
md2pdf document.md --title "Project Report"
# Page size and orientation
md2pdf document.md --page-size letter --orientation landscape
# High-quality Mermaid diagrams with custom theme
md2pdf document.md --mermaid-scale 3 --mermaid-theme forest
# Use legacy ReportLab engine (faster, no emoji)
md2pdf document.md --engine reportlab
# Disable Mermaid rendering (faster, text-only diagrams)
md2pdf document.md --no-mermaid
# Combine options
md2pdf document.md -o report.pdf --page-size a3 --title "Report"from md2pdf import convert_markdown_to_pdf_html
# Read markdown file
with open("document.md", "r") as f:
markdown_content = f.read()
# Basic conversion (emoji supported!)
result = convert_markdown_to_pdf_html(
markdown_content,
"output.pdf",
title="My Document"
)
# With custom page settings
result = convert_markdown_to_pdf_html(
markdown_content,
"report.pdf",
title="Annual Report",
page_size="A4", # Options: 'A4', 'A3', 'Letter'
orientation="portrait", # Options: 'portrait', 'landscape'
enable_mermaid=True # Enable/disable Mermaid rendering
)
# Legacy ReportLab engine (for advanced PDF features)
from md2pdf import convert_markdown_to_pdf
convert_markdown_to_pdf(
markdown_content,
"output.pdf",
page_numbers=True,
font_name="arial",
emoji_strategy="remove" # ReportLab doesn't support emoji
)- Full emoji support π - Colored emoji render natively
- Modern CSS styling - Browser-quality rendering
- Table of contents - Add
[TOC]anywhere in your markdown - Page numbers - Automatic footer pagination (X / Y format)
- Best quality - Superior rendering for modern documents
- Custom fonts - TTF font support
- Advanced PDF features - Custom headers/footers, bookmarks
- Smaller file size - Slightly more compact
- No emoji - Emoji are removed for compatibility
# Use HTML engine (default)
md2pdf document.md
# Use ReportLab engine
md2pdf document.md --engine reportlab --emoji-strategy remove- Headers (H1-H4) with colored borders
- Bold, italic,
inline code(including in lists!) - Emoji π β β π΄ π’ (full color support with HTML engine)
- Bullet lists and numbered lists with full formatting support
- Table of contents - Just add
[TOC]in your markdown! - Tables with colored headers
- Code blocks with syntax highlighting
- Horizontal rules
- Mermaid diagrams (rendered as high-quality images)
- Full Unicode/UTF-8 support (multilingual text, special characters)
Automatically renders Mermaid diagrams as high-quality PNG images:
```mermaid
graph LR
A[Start] --> B[Process]
B --> C[End]
style A fill:#90EE90
style C fill:#FFD700
```Becomes a visual diagram in the PDF!
Mermaid Features:
- Customizable themes:
default,neutral,dark,forest,base - Quality control: Scale factor 1-4 for resolution (default: 2 = high quality)
- Automatic sizing: Diagrams fit properly on pages
- Full-width diagrams: Optimized for readability
- Multiple page sizes: A4, A3, Letter
- Portrait and Landscape orientation support
- Automatic page numbering in footer (HTML engine)
- Table of contents support (HTML engine)
- Professional color scheme
- Tables with alternating row colors
- Code blocks with light gray background
- Headers with colored borders
- 2cm margins on all sides
- Full emoji rendering (HTML engine)
- Python 3.8+
- Chromium browser (via Playwright, ~250 MB)
- playwright, reportlab, markdown, pillow (installed automatically)
Convert your modern documentation to PDF:
# API Documentation π
## Quick Start β
Install the package and get started! π
### Features
- β
Easy to use
- β‘ Fast performance
- π Secure by defaultCreate professional reports with:
- Data flow diagrams
- System architecture
- Process flowcharts
- Executive summaries
Automatically generate PDFs in your pipeline:
# GitHub Actions example
- name: Generate PDF Documentation
run: |
pip install md2pdf-mermaid
playwright install chromium
md2pdf README.md -o docs/README.pdfAdd a table of contents anywhere in your markdown:
# My Document
[TOC]
## Chapter 1
Content here...
## Chapter 2
More content...The [TOC] marker will be replaced with a clickable table of contents!
from md2pdf import convert_markdown_to_pdf_html
from pathlib import Path
# Convert all markdown files
for md_file in Path("docs").glob("*.md"):
pdf_file = md_file.with_suffix(".pdf")
with open(md_file, "r") as f:
content = f.read()
convert_markdown_to_pdf_html(content, str(pdf_file), title=md_file.stem)
print(f"β Created {pdf_file}")# HTML engine (default) - emoji support
from md2pdf import convert_markdown_to_pdf_html
result = convert_markdown_to_pdf_html(
markdown_text,
"output.pdf",
enable_mermaid=True
)
# result['emoji_support'] == True
# ReportLab engine - advanced PDF features
from md2pdf import convert_markdown_to_pdf
convert_markdown_to_pdf(
markdown_text,
"output.pdf",
page_numbers=True,
font_name="arial",
emoji_strategy="remove"
)# Install Playwright
pip install playwright
# Install Chromium browser
playwright install chromiumThe PDF file is open in a viewer. Close it first, then try again.
- Check Playwright is installed:
python -c "import playwright" - Check Chromium is installed:
playwright install --force chromium - Try disabling and re-enabling Mermaid:
md2pdf file.md --no-mermaid
If you're using the ReportLab engine, emoji are not supported. Switch to HTML engine:
md2pdf document.md --engine html # or just: md2pdf document.md (HTML is default)macOS uses externally-managed Python. Always use a virtual environment:
# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate
# Install package
pip install md2pdf-mermaid
playwright install chromium
# Use the package (with venv activated)
md2pdf document.mdNote: Remember to activate the virtual environment (source venv/bin/activate) before using md2pdf.
Best solution: Use Windows Python instead of Linux Python (no sudo needed):
# Create Windows venv from WSL
python3.exe -m venv venv
venv/Scripts/pip.exe install md2pdf-mermaid
venv/Scripts/playwright.exe install chromium
venv/Scripts/md2pdf.exe document.md # Works perfectly!See WSL_SETUP.md for complete instructions.
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details
- mermaid - Diagram syntax
- reportlab - PDF generation
- playwright - Browser automation
- python-markdown - Markdown processing
- Issues: https://github.com/rbutinar/md2pdf-mermaid/issues
- Documentation: https://github.com/rbutinar/md2pdf-mermaid
- Full emoji support (v1.4.0)
- Table of contents generation (v1.4.0)
- Page numbering (v1.4.0)
- Custom CSS themes
- Image embedding from URLs
- Header/footer customization
- Multi-column layouts
- PDF metadata (author, keywords, etc.)
Version: 1.4.3 Published: 2025-12-14 PyPI: https://pypi.org/project/md2pdf-mermaid/ Status: Stable Release π
Bug Fixes:
- π Fixed missing dependency - Added
markdown>=3.0.0to all dependency configurations- Resolves
ModuleNotFoundError: No module named 'markdown'on fresh installations - Now automatically installed with the package
- Resolves
Documentation:
- π macOS Setup Guide - Comprehensive MACOS_SETUP.md documentation
- Virtual environment setup instructions for macOS users
- Troubleshooting for "externally-managed-environment" error
- Tips for aliases and global installation
- Tested on macOS 11-15 (Big Sur through Sequoia)
- Apple Silicon (M1/M2/M3/M4) and Intel support confirmed
Improvements:
- β Better installation experience on macOS
- β Updated README with macOS-specific instructions
- β All features fully tested on macOS environment
- π Fixed Mermaid diagram rendering timing issues
- β‘ Performance improvement: ~18% faster rendering
Major New Features:
- π Full emoji support - Colored emoji render natively via HTML/Chromium engine
- π Table of contents - Add
[TOC]anywhere in your markdown for automatic TOC - π Page numbering - Automatic footer pagination (X / Y format)
- π¨ HTML rendering engine - Superior quality, modern CSS styling (now default)
- β‘ Dual engine architecture - HTML (default) or ReportLab (legacy) engines
Technical Improvements:
- β Mermaid diagrams automatically sized to fit pages
- β Better diagram quality with controlled height limits
- β Professional page layout with proper margins
- β Modern CSS styling for all elements
- β Browser-grade rendering quality
How to Use:
# Emoji now work by default!
md2pdf document.md
# Table of contents
echo "[TOC]" > doc.md
md2pdf doc.md
# Legacy engine (if needed)
md2pdf document.md --engine reportlabBreaking Changes:
- None! Default engine changed to HTML, but ReportLab still available with
--engine reportlab
- π Fixed emoji removal for technical symbols (β, β, β, etc.)
- π§ Improved emoji detection accuracy
- β¨ Mermaid theme support - 5 color themes available
- β¨ Mermaid quality control - Scale factor 1-4 for resolution
- β¨ Automatic emoji removal (for PDF compatibility with ReportLab)
- π Fixed Mermaid diagram sizing issues
- π Fixed hyperlink rendering
- β¨ Full Unicode/UTF-8 support
- β¨ Customizable fonts (Arial, DejaVu, Helvetica, custom TTF)
- β¨ Bold & inline code in lists
- π Fixed encoding issues
