A Python tool to convert Markdown files to PDF format. Supports single-file and batch conversion.
Author: Amir Yunus
For a summary of changes by version, see CHANGELOG.md.
- Convert a single Markdown file to PDF
- Batch convert multiple Markdown files in a directory (recursive, includes subdirectories)
- Simple command-line or programmatic usage
- Python 3.10+
- Dependencies: see
requirements.txt
The script uses WeasyPrint when possible (best layout and typography). If WeasyPrint’s system libraries (Pango, Cairo, GLib) are not installed, it automatically falls back to xhtml2pdf (pure Python), so conversion works without extra system setup. On macOS you may see a WeasyPrint warning and then conversion will proceed with the fallback.
To use WeasyPrint and remove the warning (optional, for better PDF quality):
- macOS:
brew install pango cairo glib - Linux: install
libpango-1.0-0,libcairo2, and related packages per your distribution
Using a virtual environment is recommended:
conda create --prefix venv python=3.11 -y
conda activate ./venv
python -m pip install -r requirements.txtConvert one Markdown file to PDF:
python convert.py document.mdOutput: document.pdf in the same directory (or as specified).
Convert all Markdown files in a directory (recursively, including subdirectories):
python convert.py --batch ./markdown-folderOr with an explicit output directory:
python convert.py --batch ./markdown-folder --output ./pdf-outputconvert.py— main conversion script (single and batch)requirements.txt— Python dependencies
This project is licensed under the terms of the LICENSE file.