md2pdf
Markdown 转 PDF 技能。将 Markdown 文件转换为精美的 PDF 文档,完美支持中文、代码高亮、自定义样式。
Install via CLI (Recommended)
clawhub install openclaw/skills/skills/franklu0819-lang/markdown-to-pdf-weasyprintMarkdown 转 PDF 技能
将 Markdown 文件转换为精美的 PDF 文档,支持中文、代码高亮、自定义样式。
⭐ 推荐方案:WeasyPrint
完美支持中文,无需 LaTeX,自动处理依赖!
快速开始
# 转换 Markdown 为 PDF(推荐)
bash /root/.openclaw/workspace/skills/md2pdf/scripts/convert-weasyprint.sh input.md
# 指定输出文件名
bash /root/.openclaw/workspace/skills/md2pdf/scripts/convert-weasyprint.sh input.md output.pdf
优点
- ✅ 完美中文支持(使用 Noto Sans CJK 字体)
- ✅ 自动安装依赖(首次运行时自动安装)
- ✅ 专业排版样式(代码高亮、表格美化)
- ✅ 轻量级(无需 LaTeX,仅 Python)
- ✅ 跨平台(支持 Linux、macOS、Windows)
功能特性
- ✅ Markdown 转 PDF
- ✅ 完美中文支持(无乱码)
- ✅ 代码语法高亮(深色主题)
- ✅ 专业表格样式(斑马纹、圆角)
- ✅ 多级标题样式
- ✅ 引用块美化
- ✅ 列表、链接、图片支持
- ✅ 自定义 CSS 样式
使用方法
方法 1:WeasyPrint(推荐)⭐
适合场景: 需要完美中文显示、专业排版
# 使用 Bash 脚本(自动处理依赖)
bash scripts/convert-weasyprint.sh document.md
# 指定输出文件
bash scripts/convert-weasyprint.sh document.md output.pdf
# 直接使用 Python 脚本
python3 scripts/convert-weasyprint.py input.md output.pdf
方法 2:Pandoc(备选)
适合场景: 已安装 LaTeX 环境
bash scripts/convert.sh input.md output.pdf
方法 3:简化 HTML
适合场景: 需要在浏览器中打印
bash scripts/convert-simple.sh input.md output.pdf
脚本说明
convert-weasyprint.sh ⭐
推荐使用 - WeasyPrint 方案,完美支持中文。
特性:
- 自动检测并安装 Python 依赖(markdown、weasyprint)
- 自动检测并安装中文字体(google-noto-sans-cjk-fonts)
- 专业的 CSS 样式(代码高亮、表格美化)
- 完整的错误处理
用法:
bash scripts/convert-weasyprint.sh <输入.md> [输出.pdf]
参数:
输入.md(必需): Markdown 文件路径输出.pdf(可选): PDF 输出路径(默认:输入文件名.pdf)
示例:
# 转换单个文件
bash scripts/convert-weasyprint.sh README.md
# 指定输出路径
bash scripts/convert-weasyprint.sh README.md /tmp/readup.pdf
# 批量转换
for md in *.md; do
bash scripts/convert-weasyprint.sh "$md"
done
convert-weasyprint.py
Python 转换脚本,被 convert-weasyprint.sh 调用,也可直接使用。
用法:
python3 scripts/convert-weasyprint.py <输入.md> [输出.pdf]
功能:
- Markdown 解析(支持表格、代码块、列表)
- HTML 生成
- CSS 样式应用
- PDF 输出
convert.sh
Pandoc 传统方案(需要 LaTeX)。
用法:
bash scripts/convert.sh <输入.md> [输出.pdf]
前置要求:
pandocxelatex(LaTeX)- 中文字体
convert-simple.sh
简化版,生成 HTML 供浏览器打印。
用法:
bash scripts/convert-simple.sh <输入.md> [输出.pdf]
技术实现
WeasyPrint 方案
使用 Python 的 WeasyPrint 库进行转换:
# 1. Markdown → HTML
html_content = markdown.markdown(
md_content,
extensions=['tables', 'fenced_code', 'nl2br', 'sane_lists']
)
# 2. HTML + CSS → PDF
HTML(string=html_content).write_pdf(
output_file,
stylesheets=[CSS(string='...')]
)
CSS 样式特性:
- 中文字体:Noto Sans CJK SC
- 代码块:深色主题(#2c3e50 背景)
- 表格:蓝色表头 + 斑马纹
- 引用块:左边框 + 浅灰背景
- 响应式设计
Pandoc 方案
使用 pandoc 的 LaTeX 引擎:
pandoc input.md -o output.pdf \
--pdf-engine=xelatex \
-V CJKmainfont="Noto Sans CJK SC" \
-V geometry:margin=2cm
支持的 Markdown 特性
- ✅ 标题(h1-h6)
- ✅ 段落和换行
- ✅ 列表(有序、无序)
- ✅ 代码块(支持语法高亮)
- ✅ 表格
- ✅ 链接和图片
- ✅ 引用块
- ✅ 水平线
- ✅ 粗体和斜体
- ✅ 自动链接
依赖管理
Python 依赖
Metadata
Not sure this is the right skill?
Describe what you want to build — we'll match you to the best skill from 16,000+ options.
Find the right skillPaste this into your clawhub.json to enable this plugin.
{
"plugins": {
"official-franklu0819-lang-markdown-to-pdf-weasyprint": {
"enabled": true,
"auto_update": true
}
}
}Related Skills
zhipu-asr
Automatic Speech Recognition (ASR) using Zhipu AI (BigModel) GLM-ASR model. Use when you need to transcribe audio files to text. Supports Chinese audio transcription with context prompts, custom hotwords, and multiple audio formats.
zhipu-tts
Text-to-speech conversion using Zhipu AI (BigModel) GLM-TTS model. Use when you need to convert text to audio files with various voice options. Supports Chinese text synthesis with multiple voice personas, speed control, and output formats.
feishu-file
飞书文件发送技能。支持发送各类文件到飞书聊天,包括文档、图片、压缩包等,自动识别文件类型并处理上传。
clawhub-manager
ClawHub 技能管理工具。封装技能的发布、删除、查询和搜索功能,方便管理 ClawHub 上的技能。
md2pdf
Markdown 转 PDF 技能。将 Markdown 文件转换为精美的 PDF 文档,完美支持中文、代码高亮、自定义样式。