Raymond-Leung7
dsh-md2pdf
DSH plugin: convert Markdown to print-friendly PDF (CJK fonts, tables with repeated headers). Provides the md_to_pdf model tool.
- Stars
- 0
- Language
- Python
- Created
- Aug 15, 2026
- Updated
- Aug 15, 2026
Introduction
dsh-md2pdf
DeepSeek Harness(DSH)插件:把 Markdown 文件转换为打印友好的 PDF。 适合分镜脚本、说明文档、笔记的打印输出。
- 默认 A4 纵向,自动中文字体(SimHei / SimSun / 微软雅黑),符号回退 Segoe UI Symbol
- 表格跨页自动重复表头、按内容分配列宽
- 每页底部页码,页眉显示文档标题
- 纯本地转换,无需联网,无浏览器依赖
安装
npm 发布版(推荐):
dsh plugin --profile web add "@raymondstudio/dsh-md2pdf"
GitHub 仓库版:
dsh plugin --profile web add "github:raymondstudio/dsh-md2pdf"
本地开发版:把插件放到 profile 的 plugins/ 目录,在 profile package.json 添加
"@raymondstudio/dsh-md2pdf": "file:./plugins/dsh-md2pdf",在 cordis.patch.yml 增加
insert 条目(id: md2pdf,inject: [tools]),然后 pnpm install 并重启 dsh。
使用
重启 dsh 后,直接对模型说:
把
xxx.md转成 PDF,标题用"文档标题",A5 横向,字号 11
或显式指定全部参数:
| 参数 | 说明 |
|---|---|
input | 输入 Markdown 文件路径(必填) |
output | 输出 PDF 路径(缺省同目录同名 .pdf) |
title | 文档标题(页眉,缺省取文件名) |
pageSize | A4 / A5 / Letter(默认 A4) |
orientation | portrait / landscape |
fontSize | 正文字号 pt(默认 10.5) |
margin | 左右页边距 mm(默认 14) |
支持的 Markdown 语法
标题(# ~ ######)、段落、粗体、斜体、行内代码、无序/有序列表(含嵌套)、
引用块、围栏代码块(等宽字体 + 浅灰底)、GitHub 风格表格(跨页重复表头)、水平线、
本地图片嵌入。链接自动降级为纯文本显示。
运行要求
- Python 3,且已安装
fpdf2:pip install fpdf2 - Windows 中文字体(SimHei/SimSun/Consolas 由系统提供;其他平台自动回退到可用字体)
- 缺少 fpdf2 时工具会返回明确错误提示,不会静默失败
工作原理
lib/index.js:Cordis 插件入口,通过defineTool注册md_to_pdf工具lib/render_md.py:fpdf2 渲染器,负责 Markdown 解析与 PDF 排版(纯本地执行)
开发
# 本地测试渲染器(无需 DSH)
python lib/render_md.py input.md output.pdf --title "标题"
# 冒烟测试工具注册(在 profile 目录)
node smoke_md2pdf.mjs
License
MIT