Markdown to PDF Advanced
v1.1.1Convert Markdown files to PDF with multiple backend options (WeasyPrint, Pandoc, wkhtmltopdf). Supports syntax highlighting, tables, images, custom CSS themes, and page styling. Use when converting Markdown (.md) to PDF, generating documents from markdown, creating PDF 报告s, or any markdown-to-pdf conversion task. Triggers on markdown to pdf, md to pdf, convert markdown pdf, 生成 pdf from markdown.
运行时依赖
安装命令
点击复制技能文档
Markdown to PDF 转换器
Convert Markdown files to PDF with professional 格式化ting. Supports multiple backends for different use cases.
Backends Primary: WeasyPrint (Pure Python) Pros: No 系统 dependencies, pip 安装 only, good CSS support Cons: Slightly slower on large documents Use for: Most use cases, especially when you can't 安装 系统 packages Optional: Pandoc + wkhtmltopdf Pros: Most powerful, LaTeX support, best typography Cons: Requires 系统 package 安装ation Use for: Academic papers, complex documents, LaTeX math Quick 启动 # Using WeasyPrint (recommended, auto-安装ed) python3 scripts/md_to_pdf.py 输入.md 输出.pdf
# Using Pandoc (if 安装ed) python3 scripts/md_to_pdf.py 输入.md 输出.pdf --backend pandoc
Usage from 代理 Basic Conversion # Convert markdown to PDF exec("python3 技能s/md-to-pdf-advanced/scripts/md_to_pdf.py /path/to/输入.md /path/to/输出.pdf")
With Custom CSS # 应用ly custom theme exec("python3 技能s/md-to-pdf-advanced/scripts/md_to_pdf.py 输入.md 输出.pdf --css 技能s/md-to-pdf-advanced/as设置s/github-theme.css")
With Options # Landscape, custom margins exec("python3 技能s/md-to-pdf-advanced/scripts/md_to_pdf.py 输入.md 输出.pdf --orientation landscape --margin 15mm")
Features ✅ Syntax-highlighted code blocks ✅ Tables with styling ✅ Images (local and remote) ✅ Headers and footers with page numbers ✅ Custom CSS themes ✅ Page size and orientation options ✅ Adjustable margins CSS Themes
AvAIlable in as设置s/:
github-theme.css - GitHub-like styling minimal-theme.css - 清理 minimal look academic-theme.css - Academic paper style Troubleshooting WeasyPrint fAIls to 安装 # 安装 系统 dependencies first (Ubuntu/Debian) sudo apt-获取 安装 python3-dev libffi-dev libxml2-dev libxslt1-dev
# Then 安装 Python packages pip3 安装 weasyprint markdown Pygments
Images not showing
Use absolute paths or ensure images are relative to the markdown file location.
Fonts look wrong
WeasyPrint uses 系统 fonts. 安装 the fonts you reference in CSS:
# Ubuntu/Debian sudo apt-获取 安装 fonts-liberation fonts-dejavu
# macOS brew 安装 --cask font-liberation
Emoji display as □ (boxes) or not rendered
PDF 中 emoji(如 ✅、🔄、📋)显示为方框是因为系统缺少彩色 Emoji 字体支持。
解决方案:
# 1. 安装 Google Noto Color Emoji 字体(支持全量 Unicode Emoji) # Fedora/RHEL/CentOS dnf 安装 -y google-noto-emoji-color-fonts
# Ubuntu/Debian sudo apt-获取 安装 fonts-noto-color-emoji
# 2. 刷新字体缓存让系统识别新字体 fc-缓存 -fv
# 3. 重新转换 PDF python3 技能s/md-to-pdf-advanced/scripts/md_to_pdf.py 输入.md 输出.pdf
替代方案(如果不想安装字体):
将 Markdown 中的 emoji 替换为文字描述或 ASCII 符号:
Emoji 文字替代 ASCII 替代 ✅ [OK] 或 (完成) [x] ❌ [FAIL] 或 (失败) [ ] 🔄 [更新] 或 (刷新) ~> 📋 [列表] 或 (任务) [#] ⚠️ [警告] 或 (注意) ! 💡 [提示] 或 (建议) i 🔧 [修复] 或 (工具) ` 🐛 [BUG] 或 (缺陷) *