文档与知识 · daymade/claude-code-skills

pdf-creator

Convert markdown files to professional PDF documents with proper Chinese font support, theme system, and visual self-check. Use for Markdown → PDF, printable Markdown documents, and Markdown formatted for print or mobile reading. Prefer its CJK typography, header/footer suppression, and visual verification over manual pandoc/Chrome commands. Scope is Markdown → PDF only. Existing Word/WPS → PDF, including manuscript excerpts and layout repair, routes to daymade-docs:docx-creator; do not round-trip an authoritative Word manuscript through Markdown. Word output also routes to docx-creator.

风险提醒:蓝色 · 知晓即可AI 侦查报告
作者 daymadeGitHub daymade/claude-code-skills ↗Stars 1385许可 MIT(仓库根 LICENSE;Copyright (c) 2025 daymade;GitHub API spdx MIT)commit d5c4678cb5
agent 宿主通常会约束 skill 执行权限;风险提醒为 AI 侦查观点,不构成质量或安全保证。第三方 skill 仅作拆解与展示,安装使用风险自负,版权归原作者。

1实现原理 · 为什么它能做到

管线是 pandoc(md→HTML) + CSS 主题 + weasyprint/headless-Chrome 渲染 + poppler 自检,脚本自动补 CJK 字体栈与排版补丁——核心在 md_to_pdf.py(813 行)。

daymade-docs/pdf-creator/scripts/md_to_pdf.py
result = subprocess.run( ["pandoc", "-f", "markdown", "-t", "html"], input=md_content, capture_output=True,
注:Chrome 后端传 --no-pdf-header-footer 防默认页眉页脚(对照 SKILL Anti-Pattern 表里手动 pandoc+Chrome 的死法);weasyprint 后端直接 HTML(string).write_pdf。

后端选择按『内容×主题字体栈』自动路由,不是按是否中文:default/cjk-auto(Songti/Heiti CID TrueType)走 weasyprint,PingFang 类主题走 Chrome,因为 weasyprint 会把 PingFang SC 子集嵌入成 CID Type 0C,macOS Preview/Adobe 读不了。

daymade-docs/pdf-creator/SKILL.md
**CJK + a Songti/Heiti theme** (`default`, `cjk-auto`) → **weasyprint**. These themes embed CID TrueType, which every reader renders, so Chrome buys nothing and costs the clip described below.
注:路由被 tests/test_backend_routing.py 钉死;`--backend` 显式参数永远覆盖自动检测。这是把字体嵌入格式(pdf 阅读器兼容)知识工程化。

主题=独立 CSS 文件(themes/*.css),5 个内置主题覆盖正式/培训/手机阅读;新主题=复制 default.css 改名。

daymade-docs/pdf-creator/SKILL.md
To create a new theme: copy `themes/default.css`, modify, save as `themes/your-theme.css`.
注:mobile 主题 148×210mm 专为微信/手机阅读;warm-terra-menu 是为菜单长文本换行加固的变体(Menlo unicode-range 修内联代码 CJK 空字)。

CJK 排版双层防御:Layer 1 自动注入 CSS 补丁(table-layout: fixed、keep-all、th nowrap 等,不改用户源文件);Layer 2 渲染后用 pdftotext -layout 按『中文文案排版指北』扫孤儿字符/破括号等反模式并警告。

daymade-docs/pdf-creator/SKILL.md
The patch: - `table { table-layout: fixed; width: 100% }` — equal column widths prevent weasyprint auto-layout from squeezing one column to ~10% width when an adjacent column has 5x more content
注:Layer 2 只警告不自动改——SKILL 明言按 CLAUDE.md『禁止隐式行为』:静默改写 markdown 会掩盖源本身的问题。

Chrome 裁剪缺陷被研究到像素级并配双形态检查:Chrome 的 @page clip path 会切掉越过内容框的表格右边框(538.90pt vs 545.18pt),且对象仍在 PDF 里、光看预览/坐标都发现不了——check_table_borders.py 提供 ink 检查 + --reference 对照两种形态,只有后者对 Chrome 渲染是有效裁决。

daymade-docs/pdf-creator/SKILL.md
It takes two forms, and for a Chrome-rendered PDF only the second one is a verdict.
注:脚本 docstring 给出实测:'a table styled with vertical rules and no cell fills, rendered through Chrome past the clip, loses its right border from the object layer entirely; the ink check then reports 5/5 promised rules painted — PASS'——这是把『为什么人工验不出』的机理写成了检查。

视觉自检强制化:每次生成自动 pdftoppm 出每页 PNG(放系统临时目录,绝不落工作树),打印 checklist 提醒逐页 Read;表格文件须跑 border check 才放行。

daymade-docs/pdf-creator/SKILL.md
Converts each page to PNG via `pdftoppm` (poppler-utils) into a `<pdf-name>/` subdirectory under the **system temp dir** (NOT next to the PDF — previews are a throwaway self-check artifact and must never linger in your working tree / git repo).
注:--no-preview 只关 PNG 不关义务:批量模式要求对输出再跑 check_table_borders.py。

2核心能力

01Markdown → 专业 PDF(中文排版 + 主题系统),单文件或批量
025 个内置主题(default/cjk-auto/warm-terra/warm-terra-menu/mobile)与自定义主题机制
03weasyprint/Chrome 双后端自动路由(内容×主题字体栈)与显式覆盖
04自动 CJK 排版补丁 + 渲染后排版 lint(孤儿字符/破括号/标点断行)
05Chrome 裁剪检测:ink 检查 + --reference 双后端对照(唯一对 Chrome 的裁决形态)
06强制视觉自检:逐页 PNG + checklist(temp dir 不污染工作树)

3外部依赖

类型依赖
clipandoc(markdown→HTML)
packageweasyprint(uv run --with weasyprint / pip install)
cliGoogle Chrome(headless --print-to-pdf 后端)
clipoppler:pdftoppm(预览 PNG)/ pdftotext / pdfinfo(排版 lint)
packagepdfplumber / pillow / numpy(check_table_borders,uv --with)

4风险提醒 风险提醒:蓝色 · 知晓即可

风险提醒:蓝色 · 知晓即可
  • Chrome 裁剪是结构性缺陷,边界案例仍可能漏 — 双形态检查只对『本 skill 产出的 PDF』校准;外部工具生成的 PDF 上 pdfplumber 可能把装饰误组装成表格产生假阳性(SKILL 自述),此时失败应视为『去人眼看』而非裁决。
  • 字体/系统依赖面宽 — 要 Songti/PingFang 字体 + pandoc + weasyprint 或 Chrome + poppler;缺字体时中文出方框,缺 weasyprint 时自动降级 Chrome(带警告)。
  • 验证义务重 — 逐页 Read + 表格 border check 是硬要求;--no-preview 批量场景要求另行跑 check,流程上易被跳过(SKILL 已反复强调)。
  • 预置网络 — 首次使用需 PyPI 拉包;无网/受限环境需预先安装 weasyprint/pdfplumber。
风险提醒:蓝色,知晓即可。纯本地工具链(pandoc/weasyprint/Chrome/poppler),运行期零网络外发、零凭证读取;写出的只有用户指定 PDF 与系统临时目录的自检 PNG。注意:首次使用需 uv/pip 拉取 weasyprint/pdfplumber 等(官方 PyPI,可预期);DYLD_LIBRARY_PATH 仅为进程内追加。

5第二遍独立确认

  • [ok] pandoc→HTML→渲染器管线 — md_to_pdf.py subprocess.run(["pandoc","-f","markdown","-t","html"]) + _render_weasyprint/_render_chrome 均存在。
  • [ok] 后端按内容×主题路由 — _detect_backend 中 _WEASYPRINT_SAFE_CJK_THEMES={'default','cjk-auto'} 与 SKILL 路由表一致;test_backend_routing.py 存在。
  • [ok] Chrome clip 缺陷数字 — SKILL 与 check_table_borders.py docstring 均载 538.90pt/545.18pt 与 '5/5 promised rules painted — PASS' 反例,跨文件一致。
  • [ok] 预览进 temp dir 而非工作树 — 代码 preview_dir = Path(tempfile.gettempdir()) / 'pdf-creator-previews' / pdf_path.stem;SKILL 同述。
  • [ok] Layer1 CSS 补丁 / Layer2 lint 不隐改源 — _TYPOGRAPHY_CSS_PATCH 注入与 pdftotext -layout 扫描代码均在;无对用户 md/css 的写回路径。
  • [ok] 无网络无凭证 — 代码扫描零 curl/requests/API key;env 读取仅 DYLD_LIBRARY_PATH(进程内)。
  • [ok] 元数据 — GitHub API:MIT / 1385 stars / pushed 2026-09-09T12:33:29Z;本地 HEAD==pin d5c4678。

6结论

  • 中文 PDF 质量关卡完备:字体嵌入格式兼容(CID TrueType 路由)、排版 lint、Chrome 裁剪检测都有脚本与测试兜底。
  • 对『为什么手动流程会翻车』的机理研究极深(clip 的对象层还在但不上墨),并把它写成可执行检查而非提醒。
  • 主题系统让培训/正式/手机阅读一次转换多版本,纯 CSS 自定义门槛低。
  • 卫生与纪律:自检产物不落工作树、绝不静默改写源 markdown——适合进团队流水线。
  • 适合:适合把中文 markdown 出正式/培训/手机版 PDF 的个人与团队(合同、讲义、课程大纲、微信分享件);要求装了 pandoc + weasyprint 或 Chrome + poppler 且愿意执行逐页视觉验证。
    不适合:不适合已有 Word/WPS 权威稿转 PDF(那是 docx-creator 的 word-to-pdf 流程,禁止 markdown 往返);不适合无中文字体/离线的环境;像素级版式控制(每页精确布局)超出 CSS 渲染能力。
    安装 agent 直装可复制
    ① 本站镜像 更新 2026-09-09
    方式 A · 人下载镜像包下载 pdf-creator.tar.gz
    sha256: 77a0f5b23369e727…
    方式 B · JSON 格式安装指南,复制给 agent
    安装指南
    agent 读 JSON 指南后会自动从本站下载安装,无需更多说明。
    ② 上游 GitHub · 原始来源
    能访问 GitHub?直接去上游安装(实时版,可能已更新)GitHub 原始 ↗
    本页镜像锁定 commit d5c4678cb5;上游为实时仓库。
    来源信息 GitHub 原始
    作者 / 仓库daymade / daymade/claude-code-skills
    Stars1385
    最近推送2026-09-09
    本 skill commitd5c4678cb5
    许可MIT(仓库根 LICENSE;Copyright (c) 2025 daymade;GitHub API spdx MIT)
    本站信息
    收录日期2026-09-06
    分类文档与知识
    侦查报告AI 侦查 · 2 遍 · 2026-09-06
    本站镜像与 GitHub 原始是不同来源:本站锁定 commit 快照经 /r2 分发;GitHub 为实时上游,内容可能已更新。
    同分类邻近