用 python-pptx 写"现代化中文制度 / 党政 / 企业宣贯 PPT"(含决议书提报、评审报告、管理办法、培训宣贯等 23 页量级 deck)。当用户要求程序化生成 PPT 且抱怨"老土 / 字体丑 / 表格乱 / 文字溢出 / 中文字体 fallback / 缺架构图"时启用——`python-pptx` 默认 API 一堆坑必须主动避开。提供:路径决策 / 设计 token / 12 个 helper 全套 / 7 个致丑反模式 / 12 个关键技巧 / LibreOffice 渲染验证闭环 / 跨平台中文字体生效 lxml 写法 / 配套 draw.io 画架构图选型(中文字体、配色、8 大坑、嵌入 PPT 链路)。
npx skills add https://github.com/pcliangx/AppGenesisForge --skill agf-writing-pptx-reports
> 沉淀自《AI 4A 架构评审管理办法》v1.0 PPT 实战(23 页,GAC 红主调,含双视图嵌入流程图),全部踩过 + 验证过的坑与方法。重型参考材料在 references/,按下方索引按需 Read 全文,不要凭记忆写代码。
| 信号 | 用本 skill |
|---|:--:|
| 需要程序化生成 PPT(数据驱动 / 模板批量 / 内容版本化) | ✅ |
| 中文制度 / 党政 / 企业内部宣贯 deck | ✅ |
| 用户反馈"老土 / 字体丑 / 表格乱 / 文字溢出 / 中文字体 fallback" | ✅ |
| 内容会反复迭代,PPT 必须从源码可重生成 | ✅ |
| 需要 mermaid 流程图嵌入 + 双视图卡片化 | ✅ |
| 高度自由排版 / 视觉冲击型营销 deck | ❌ 直接 Keynote / Figma |
| 复杂动画 / 视频嵌入 | ❌ python-pptx 弱项 |
| 一次性单页海报 | ❌ 直接画 |
| 要 docx / xlsx | ❌ 转 writing-docx-reports / xlsx skill |
| 路径 | 何时选 | 代价 |
|---|---|---|
| 手动复制 .pptx 模板编辑 | 一次性 deck / 设计师介入 / 不需重生成 | 几分钟;后续维护成本高 |
| pptx skill 局部改 | 已有 .pptx 做小幅修改(≤ 5 张 slide / 仅换文字)| 中等;不适合从零生成 |
| 基于模板 + python-pptx 混合 ⭐ | 仓库已有 .pptx 模板 / 视觉风格已定 / 需版本化 + 重生成 | 一次 ~500 行;保留模板视觉投入 + 代码可重跑 |
| python-pptx 全定制 | 没现成模板 / 视觉自己定义 / 跨平台中文 / 23+ 页量级 | 一次 ~800 行 Python,复用率 90% |
判定经验:
template/ 已有 1 个 .pptx 模板(Template.pptx,coral 团队风)→ 默认走"基于模板 + python-pptx 混合",不要重造视觉template-*-guide.md| 场景 | 必读(Read 全文) |
|---|---|
| 走"基于模板 + python-pptx 混合"路径(动手前) | references/template-based-generation.md(7 步流程 / 模板分析三件套 / Placeholder vs Shape / 关键文件指针)+ 对应 template-*-guide.md(如 template-team-guide.md)|
| 写 helper / 设计 token / 字号 layout / 品牌色板(任何写代码前) | references/design-tokens-and-techniques.md(设计 token + 12 个关键技巧完整代码 + 品牌色获取 3 步)+ template.py(可直接 python3 template.py 跑样例)|
| deck 缺架构 / 流程 / 矩阵图(走 draw.io 前) | diagram-generation-guide.md(500 行:安装 CLI / mxGraph 模板 / AGF token / 字号体系 / 8 大致丑坑 / 批量工作流 / 嵌入链路)|
| mermaid 出图嵌 PPT / 多 PNG 合 PDF 提报 / 查外部资源链接与沉淀来源 | references/rendering-and-embedding.md |
| 操作 .pptx 底层(unpack / thumbnail / pack) | .claude/skills/pptx/SKILL.md(Anthropic 低层 skill)|
| 用途 | 工具 | 装法 |
|---|---|---|
| PPT 生成 | python-pptx ≥ 1.0 | pip3 install --user --break-system-packages python-pptx |
| XML 微调(EA 字体 / 表格属性 / 阴影) | lxml | 通常已装 |
| PPT → PDF(实际渲染验证)| soffice(LibreOffice)| brew install --cask libreoffice |
| PDF → PNG(视觉验证)| pdftocairo(poppler)| brew install poppler |
| 多 PNG → PDF 合并 | sips(系统自带)+ pdfunite | brew install poppler |
| mermaid 流程图 | mmdc | brew install mermaid-cli |
⚠ 不要装 PrinceXML(商业 + 免费版水印);不要走 pandoc --pdf-engine=prince 这条路。
diagram-generation-guide.md 全文(见上方索引)_fix_ph_font(ph, name="PingFang SC"));别图用 Heiti SC、PPT 用 PingFang SC 造成跨页面字体跳变| # | 反模式 | 为什么丑 | 正确做法 |
|:-:|---|---|---|
| 1 | 顶部厚色带(≥0.5")每页都重复 | 压死页面空间 + 视觉疲劳 | 6pt 极细线 + 右上 140pt 装饰大数字 |
| 2 | 每页同一 header(title, page) 通用模板 | 章节同质化、无层次感 | 章节扉页与内容页分两种 layout |
| 3 | 表格全网格(Excel 风)+ 默认 banding | 老土 + 信息密度低 | 表头深色 + 0 内边框 + 自定义斑马纹 |
| 4 | 一页 5+ 种饱和色(绿/蓝/红/橙/紫) | 眼花、权重失序 | 1 主色 + 1 强调色 + 灰阶 + 白 |
| 5 | 全屏文字墙(一页 >100 字)| 没人会读完 | 卡片化(每个信息单元独立矩形) |
| 6 | 标题用艺术字 / 阴影 / 3D / 渐变铺底 | 党政"信封风" | 简洁字体 + 1pt 横线分隔 |
| 7 | emoji 滥用(🚀 ✅ 🎉 等活泼感)| 制度文件不严肃 | 仅 ⚠ ⛔ 🔒 类警示性图标 |
| # | 坑 | 正解 |
|:-:|---|---|
| 1 | font.name 只写 <a:latin>,中文跨平台 fallback 丑字体 | set_font 用 lxml 显式写 <a:ea> + <a:cs>(技巧 #1)|
| 2 | set_font(run) 改不动 placeholder 中文字体(<a:ea> 继承自 master)| placeholder 一律 _fix_ph_font(ph, ...),自加 textbox 才用 set_font(run, ...) |
| 3 | textbox 默认 margin 非 0 → 文字神秘偏右/偏下 | margin_left/right/top/bottom = Emu(0) |
| 4 | 大字号装饰数字被自动换行("01" → 两行)| word_wrap=False;宽度 ≥ 字符数 × 0.6 × 字号pt / 72 |
| 5 | 表格默认 banding 出怪横纹 / 行高失控 | tblPr 关 firstRow/bandRow + 显式 row.height,斑马纹手动填色 |
| 6 | shape.fill = None 不是"无填充",是"默认"(会有边)| fill.background() / line.fill.background() |
| 7 | 模板自带样例 slide 污染输出 | 加载后立即 clear_template_slides(prs)(template.py 提供)|
| 8 | LibreOffice 渲染页数 < len(prs.slides) 误判为代码 bug | 模板含"工具说明页"不被渲染,先看 template-*-guide.md |
最致命的错误:只用 python-pptx 读回验证文件合法性,不看实际渲染。字符溢出 / 表格被截 / 文字遮挡 / 行高失控 / 中文字体 fallback——只能靠 LibreOffice 渲染 PDF + 看 PNG 才能发现。
python3 build-ppt.py # 1. 生成
cd /tmp && rm -rf preview && mkdir preview && cd preview
soffice --headless --convert-to pdf /path/to/output.pptx # 2. 转 PDF(实际渲染)
pdftocairo -png -r 100 output.pdf p # 3. 转 PNG(视觉)
# 4. 用 Read tool 看关键页(封面、表格页、嵌入图页、警示页)
# 5. 发现问题 → 改 build-ppt.py → 回到 1
每页 3 步检查:✓ 文字是否被截断 / 溢出框 / 遮挡? ✓ 中文字体是否正确(不是 fallback 到丑字体)? ✓ 表格 / 列宽是否合理,斑马纹是否生效?
通用(所有路径都查):
<a:ea> + <a:cs>)firstRow / bandRow(防 banding)word_wrap=Falsemargin_left/right = 0line_spacing 显式设置(标题 1.0 / 正文 1.45)N / TOTALheight=Inches(N) 等比缩放(不变形)python3 build-ppt.py 一键重生成基于模板路径专项(增加 4 项):
clear_template_slides(prs) 清空所有样例 slide_fix_ph_font(ph, ...) 修字体(不是 set_font(run, ...))len(prs.slides) —— 不一致时确认是"模板含工具说明页"而非代码 bugtemplate-*-guide.md(如 template-team-guide.md),知道该模板的可用 layout / 配色 / 字体坑把上文 Checklist 反过来念即是 anti-prompt(每条 [ ] → "不要 X"),不在此重列。Checklist 未覆盖的唯一一条额外禁令:
- 不要 commit 渲染产物(HTML / PDF / .pyc)— 在 .gitignore 里
Comprehensive document creation, editing, and analysis with support for tracked changes, comments, formatting preservation, and text extraction. When Claude needs to work with professional documents (.docx files) for: (1) Creating new documents, (2) Modifying or editing content, (3) Working with tracked changes, (4) Adding comments, or any other document tasks
Comprehensive PDF manipulation toolkit for extracting text and tables, creating new PDFs, merging/splitting documents, and handling forms. When Claude needs to fill in a PDF form or programmatically process, generate, or analyze PDF documents at scale.
Presentation creation, editing, and analysis. When Claude needs to work with presentations (.pptx files) for: (1) Creating new presentations, (2) Modifying or editing content, (3) Working with layouts, (4) Adding comments or speaker notes, or any other presentation tasks
Create beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.
Use this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.
Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.
Use this skill any time a .pptx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates, layouts, speaker notes, or comments. Trigger whenever the user mentions \"deck,\" \"slides,\" \"presentation,\" or references a .pptx filename, regardless of what they plan to do with the content afterward. If a .pptx file needs to be opened, created, or touched, use this skill.
Create and edit Obsidian Flavored Markdown with wikilinks, embeds, callouts, properties, and other Obsidian-specific syntax. Use when working with .md files in Obsidian, or when the user mentions wikilinks, callouts, frontmatter, tags, embeds, or Obsidian notes.
Take pcliangx/agf-writing-pptx-reports from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.
The instructions reference pip, brew.
Without those the skill loads but fails at the first command.