Convert Markdown files (including Mermaid diagrams) to PDF using Chrome headless. Use when asked to "export to PDF", "convert md to pdf", "generate PDF from markdown", or when docs need to be shared as PDF. Supports Mermaid diagrams, tables, code blocks with syntax highlighting, and all standard markdown.
Convert .md files to styled PDF with full Mermaid diagram rendering via Chrome headless. No pandoc, no LaTeX required — just Node.js + Chrome.
.md filemarked + mermaid CDNThe script is at scripts/md-to-pdf.js relative to this skill's directory. When activating this skill, resolve the path from the skill file location.
# Agent resolves SKILL_DIR from the activated skill path, then:
node "$SKILL_DIR/scripts/md-to-pdf.js" <input.md> [output.pdf]
Examples by environment:
# Unix/Mac (Claude Code default)
node ~/.agents/skills/markdown-to-pdf/scripts/md-to-pdf.js input.md
# Windows PowerShell
node "$env:USERPROFILE\.agents\skills\markdown-to-pdf\scripts\md-to-pdf.js" input.md
# Windows Git Bash / MSYS2
node ~/. agents/skills/markdown-to-pdf/scripts/md-to-pdf.js input.md
# Codex / other agents — use absolute path from skill registry
node /path/to/skills/markdown-to-pdf/scripts/md-to-pdf.js input.md
If output.pdf omitted → saves as <input>.pdf in same directory.
Batch (Unix):
for f in docs/*.md; do node "$SKILL_DIR/scripts/md-to-pdf.js" "$f"; done
Batch (Windows PowerShell):
Get-ChildItem docs\*.md | ForEach-Object { node "$SKILL_DIR\scripts\md-to-pdf.js" $_.FullName }
.md and optional output .pdf pathstart "" output.pdf (Windows) or open output.pdf (Mac)--headless=new support, i.e. Chrome ≥ 112)node_modulesScript checks in order:
C:\Program Files\Google\Chrome\Application\chrome.exeC:\Program Files (x86)\Google\Chrome\Application\chrome.exe/Applications/Google Chrome.app/Contents/MacOS/Google Chrome/usr/bin/google-chrome, /usr/bin/chromium-browser| Element | Rendering |
|---|---|
| Mermaid diagrams | ✅ Full SVG render (same as VS Code preview) |
| Tables | ✅ Styled with borders |
| Code blocks | ✅ Syntax-highlighted background |
| Headings | ✅ Styled with blue accent |
| Print layout | ✅ @media print — full-width, page breaks |
Install packages locally and update script imports:
npm install marked mermaid
Then in script replace CDN <script src="..."> with local paths.
Handles: .md → .pdf with Mermaid, standard markdown, code blocks
Does NOT handle: DOCX export, custom fonts, password-protected PDFs, HTML→PDF without markdown