When to Use This Skill
- User mentions a
.mdfile and wants to convert it to PDF - Export markdown notes, documentation, or README files as PDF
- Generate printable PDF from markdown with styling
Prerequisites
markdown-pdf— converts markdown to PDF using markdown-it-py + PyMuPDF
Pre-flight check:
python3 -c "import markdown_pdf; print('markdown-pdf', markdown_pdf.__version__)"
Install if missing:
pip install mythril-agent-skills[md-to-pdf]
Or standalone:
pip install markdown-pdf
Workflow
- User provides a markdown file path (and optionally an output path)
- Run the conversion script
- Report the output PDF path to the user
All commands use:
python3 scripts/md_to_pdf.py [options] <input.md>
The script path is relative to this skill directory.
Command Reference
Basic conversion
# Convert to PDF (output next to input: README.md -> README.pdf)
python3 scripts/md_to_pdf.py document.md
# Specify output path
python3 scripts/md_to_pdf.py document.md -o /path/to/output.pdf
Table of contents
# Generate TOC from h1-h2 headings (default: no TOC)
python3 scripts/md_to_pdf.py document.md --toc 2
# TOC from h1-h3
python3 scripts/md_to_pdf.py document.md --toc 3
Paper size and orientation
# Use Letter paper
python3 scripts/md_to_pdf.py document.md --paper-size Letter
# A4 landscape
python3 scripts/md_to_pdf.py document.md --paper-size A4-L
Supported sizes: A3, A4, A5, A6, B4, B5, Letter, Legal (append -L for landscape).
Custom CSS
# Apply custom CSS file
python3 scripts/md_to_pdf.py document.md --css style.css
PDF metadata
# Set title and author
python3 scripts/md_to_pdf.py document.md --title "User Guide" --author "Jane Doe"
Optimize file size
python3 scripts/md_to_pdf.py document.md --optimize
Combining options
python3 scripts/md_to_pdf.py README.md \
-o guide.pdf \
--toc 2 \
--paper-size A4 \
--title "Project Guide" \
--author "Team" \
--optimize
Guidelines
- Output defaults to same directory as input:
notes.mdproducesnotes.pdfin the same folder - Images: relative image paths in markdown are resolved from the markdown file's directory
- UTF-8: full Unicode support for any language
- Large documents: use
--optimizeto reduce file size