← 返回
未分类 中文

Markdown to PDF Advanced

Convert Markdown files to PDF with multiple backend options (WeasyPrint, Pandoc, wkhtmltopdf). Supports syntax highlighting, tables, images, custom CSS theme...
使用多个后端(WeasyPrint、Pandoc、wkhtmltopdf)将 Markdown 文件转为 PDF,支持语法高亮、表格、图片和自定义 CSS 主题。
20181112523 20181112523 来源
未分类 clawhub v1.1.1 1 版本 99800 Key: 无需
★ 1
Stars
📥 479
下载
💾 0
安装
1
版本
#latest

概述

Markdown to PDF Converter

Convert Markdown files to PDF with professional formatting. Supports multiple backends for different use cases.

Backends

Primary: WeasyPrint (Pure Python)

  • Pros: No system dependencies, pip install only, good CSS support
  • Cons: Slightly slower on large documents
  • Use for: Most use cases, especially when you can't install system packages

Optional: Pandoc + wkhtmltopdf

  • Pros: Most powerful, LaTeX support, best typography
  • Cons: Requires system package installation
  • Use for: Academic papers, complex documents, LaTeX math

Quick Start

# Using WeasyPrint (recommended, auto-installed)
python3 scripts/md_to_pdf.py input.md output.pdf

# Using Pandoc (if installed)
python3 scripts/md_to_pdf.py input.md output.pdf --backend pandoc

Usage from Agent

Basic Conversion

# Convert markdown to PDF
exec("python3 skills/md-to-pdf-advanced/scripts/md_to_pdf.py /path/to/input.md /path/to/output.pdf")

With Custom CSS

# Apply custom theme
exec("python3 skills/md-to-pdf-advanced/scripts/md_to_pdf.py input.md output.pdf --css skills/md-to-pdf-advanced/assets/github-theme.css")

With Options

# Landscape, custom margins
exec("python3 skills/md-to-pdf-advanced/scripts/md_to_pdf.py input.md output.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 assets/:

  • github-theme.css - GitHub-like styling
  • minimal-theme.css - Clean minimal look
  • academic-theme.css - Academic paper style

Troubleshooting

WeasyPrint fails to install

# Install system dependencies first (Ubuntu/Debian)
sudo apt-get install python3-dev libffi-dev libxml2-dev libxslt1-dev

# Then install Python packages
pip3 install weasyprint markdown Pygments

Images not showing

Use absolute paths or ensure images are relative to the markdown file location.

Fonts look wrong

WeasyPrint uses system fonts. Install the fonts you reference in CSS:

# Ubuntu/Debian
sudo apt-get install fonts-liberation fonts-dejavu

# macOS
brew install --cask font-liberation

Emoji display as □ (boxes) or not rendered

PDF 中 emoji(如 ✅、🔄、📋)显示为方框是因为系统缺少彩色 Emoji 字体支持。

解决方案:

# 1. 安装 Google Noto Color Emoji 字体(支持全量 Unicode Emoji)
# Fedora/RHEL/CentOS
dnf install -y google-noto-emoji-color-fonts

# Ubuntu/Debian
sudo apt-get install fonts-noto-color-emoji

# 2. 刷新字体缓存让系统识别新字体
fc-cache -fv

# 3. 重新转换 PDF
python3 skills/md-to-pdf-advanced/scripts/md_to_pdf.py input.md output.pdf

替代方案(如果不想安装字体):

将 Markdown 中的 emoji 替换为文字描述或 ASCII 符号:

Emoji文字替代ASCII 替代
-----------------------------
[OK](完成)[x]
[FAIL](失败)[ ]
🔄[更新](刷新)~>
📋[列表](任务)[#]
⚠️[警告](注意)!
💡[提示](建议)i
🔧[修复](工具)``
🐛[BUG](缺陷)*

版本历史

共 1 个版本

  • v1.1.1 当前
    2026-05-03 06:35 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

office-efficiency

Excel / XLSX

ivangdavila
创建、检查和编辑 Microsoft Excel 工作簿及 XLSX 文件,支持可靠的公式、日期、类型、格式、重算及模板保留功能。
★ 381 📥 144,435
dev-programming

Gitlab Mr Review Pipeline

20181112523
自动化 GitLab MR 代码审查流水线,利用 AI 生成审查报告并邮件发送给提交人。
★ 0 📥 469
office-efficiency

Word / DOCX

ivangdavila
创建、检查和编辑 Microsoft Word 文档及 DOCX 文件,支持样式、编号、修订记录、表格、分节符及兼容性检查等功能。
★ 457 📥 151,886