---
name: pptx
description: "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. This skill is a four-stage navigator (design → graphics → file ops → QA): it establishes a design system by bridging the ui-design skill, draws editable graphics (native vector shapes for diagrams, embedded SVG with PNG fallback for art that ungroups in PowerPoint), and enforces OPC compliance — not just a PptxGenJS/OPC file-operation manual."
license: Proprietary. LICENSE.txt has complete terms
---

# PPTX Skill

## 这是什么 skill

做 PPT 的本质是「前端/平面设计 + 内容 + 文件操作」三件事，不是把 API 堆出来。本 skill 是一个**向导**：
按「设计 → 图形 → 落盘 → QA」四阶段牵着走 —— 既会用 PptxGenJS/OPC 操作文件，也会按设计系统排版、用矢量做可编辑配图。

> 📍 **寻址说明**：本 skill 内的 `[x](x)` / `scripts/x` 链接相对**本技能目录**（即系统提示「可用技能」列表里本卡片给出的 `技能目录:` 绝对路径），**不是相对当前工作目录(cwd)**——用该绝对目录拼成绝对路径再 Read/执行。引用同仓的 `ui-design` 技能时同理：用列表里 **ui-design 自己卡片**的绝对目录，别用 `../ui-design/`（详见 [design.md](design.md) 顶部）。

## 四阶段向导（按序走）

**阶段 0 · 路由** —— 先判断要干嘛：
- 读内容 / 抽文本 → `python -m markitdown x.pptx`（到此为止，不进后续阶段）。
- 拿已有 pptx 当模板改 → 读 [editing.md](editing.md)（unpack→改→pack）；设计判断仍走阶段 1。
- 从零创建 → 往下走阶段 1–4。

**阶段 1 · 设计**（除非用户明确只要纯文本草稿/不要排版，否则**必做**）—— 先立设计系统，别直接画：
> ⛔ **最高优先级·强制**：**一切样式与设计**——配色 / VI / 字体配对 / 字阶 / 版式 / 视觉节奏 / 避免 AI 味——**必须借同仓 `ui-design` skill 来定**，不要自己拍脑袋，也不要靠本文里现成的零碎素材（已删，原因见「样式与设计」节）。页面好不好看由这一步决定。

读 [design.md](design.md)：它会带你用 ui-design 卡片的**绝对目录**读 `ui-design/SKILL.md` 立设计系统，并把 web 设计翻译到 PPT 的英寸/pt 画布。PPT 落地的尺寸/间距/避坑等 **PPT 特有硬约束**也在 design.md（ui-design 是 web 语境给不了）。

**阶段 2 · 图形** —— 按下面「图形决策规则」选路线：结构图用 [pptxgenjs.md](pptxgenjs.md) + `scripts/deck_helpers.mjs`；美术配图用 SVG，读 [svg.md](svg.md)。

**阶段 3 · 落盘** —— PptxGenJS 生成（**Node 跑，不要 Bun**，见 pptxgenjs.md 文首铁律）。
**用了 SVG 就必跑** `node scripts/svg_fallback.mjs deck.pptx`（补真 PNG 兜底 + OPC 合规重打包）。

**阶段 4 · QA** —— `python scripts/opc_check.py deck.pptx`（硬门槛）→ markitdown 内容核对 → 视觉 QA（见下）。

### 图形决策规则（阶段 2 的核心）

| 内容 | 用什么 | 备注 |
|------|--------|------|
| 标题 / 正文 / 项目符号 / 表格 —— **任何文字** | 原生 `addText` | 可编辑可重排；**绝不**烤进图片 |
| 框图 / 流程图 / 时序 / 色块布局 | 原生 `addShape` | 原生对象，点选即改；复用 `scripts/deck_helpers.mjs`。**拿不准时的默认** |
| 背景 / 渐变 / 插画 / 图标 / 曲线 / Logo | **SVG** + `svg_fallback.mjs` | 矢量丰富，PowerPoint 365 可「转换为形状」编辑；见 [svg.md](svg.md) |
| 真实照片 / 已有位图 | `addImage(png/jpg)` | 封面/封底装饰 ≤2 张为宜 |

一句话：**文字 addText，结构 addShape，美术 SVG，照片 addImage。**

### 能力地图（要细节读哪份）

| 你要做 | 读这份 |
|--------|--------|
| 立设计系统（配色/VI/字阶/版式） | [design.md](design.md)（桥接 `ui-design`） |
| SVG 可编辑配图 + 兜底管线 | [svg.md](svg.md) |
| 复用矢量原语（卡片/节点/箭头/标题/页脚） | `scripts/deck_helpers.mjs` |
| PptxGenJS API（文字/形状/图表/表格） | [pptxgenjs.md](pptxgenjs.md) |
| 改模板（unpack/pack） | [editing.md](editing.md) |
| OPC 合规校验/重打包（硬门槛） | `scripts/opc_check.py` |
| SVG 兜底修复 + 合规重打包 | `scripts/svg_fallback.mjs` |
| 端到端范例（3 页混合） | `examples/hybrid_example.mjs` + `examples/README.md` |

---

## Reading Content

```bash
# Text extraction
python -m markitdown presentation.pptx

# Visual overview
python scripts/thumbnail.py presentation.pptx

# Raw XML
python scripts/office/unpack.py presentation.pptx unpacked/
```

---

## Editing Workflow

**Read [editing.md](editing.md) for full details.**

1. Analyze template with `thumbnail.py`
2. Unpack → manipulate slides → edit content → clean → pack

---

## Creating from Scratch

**Read [pptxgenjs.md](pptxgenjs.md) for full details.**

Use when no template or reference presentation is available.

先按「图形决策规则」分路：**结构图用原生 `addShape`**（复用 `scripts/deck_helpers.mjs` 的卡片/节点/箭头/标题/页脚，省得重踩 PptxGenJS 坑），**美术配图用 SVG**（读 [svg.md](svg.md)，生成后必跑 `scripts/svg_fallback.mjs`），文字一律原生 `addText`。`examples/hybrid_example.mjs` 是 3 页混合的可临摹范例。

---

## 样式与设计 = 一律走 ui-design（本节已删除内嵌设计素材）

> ⛔ **最高优先级·强制**：配色 / VI / 字体配对 / 字阶 / 版式 / 视觉节奏 / 避免 AI 味——这些**「样式与设计」决策一律去 `ui-design` skill 立**（见 [design.md](design.md) 第一步，用系统提示「可用技能」列表里 **ui-design 卡片给的绝对目录** 读它，**别用相对 `../ui-design/`**——Read 锚 cwd 会解析错）。
>
> 这里**曾内嵌过配色表 / 字体配对表 / 版式清单，现已全部删除**。删除原因：内嵌一份"看着够用"的设计素材，会诱导你**就地取材、自满、跳过 ui-design**，做出千篇一律的 AI 味页面。设计智能只有**一个真相源**（ui-design），pptx 只负责"引用它 + 把 web 设计翻译到 PPT 画布"，不复制、不另存一份会漂移的副本。
>
> 兜底：万一在系统提示和 `Glob('**/ui-design/SKILL.md')` 里都定位不到 ui-design，**才**回退到通用设计常识自行决定（仅此一种例外）。

**PPT 特有的硬约束**——尺寸（pt）/ 间距（英寸）/ PptxGenJS 避坑（ui-design 是 web 1920×1080 px 语境，给不了英寸+pt 这套）——见 **[design.md](design.md) 第三步及其后的「PPT 落地硬约束 / 避坑」**。那是 pptx 不可替代的增量，照它执行。

---

## QA (Required)

**Assume there are problems. Your job is to find them.**

Your first render is almost never correct. Approach QA as a bug hunt, not a confirmation step. If you found zero issues on first inspection, you weren't looking hard enough.

### Compliance QA (硬门槛，先做)

pptx 本质是 OPC zip 包。PowerPoint 打开时做**严格 OPC 校验**，包不合规会判「需要修复」、
修复后内容丢失。**「某个库能 load/import ≠ PowerPoint 能干净打开」**——python-pptx 很宽容，
会忽略目录条目等问题照样加载成功，**绝不要**拿「python-pptx 能否重新打开」当验证通过的判据
（这正是损坏包溜过验收闸门的根因）。忠实校验用：

```bash
python scripts/opc_check.py output.pptx
```

退出码非 0 即不合规，按提示一步修回：`python scripts/opc_check.py output.pptx --repack output.fixed.pptx`。

> 用 PptxGenJS「从零创建」时，**生成脚本必须用 Node 跑（`node x.mjs`），不要 `bun run`**——
> Bun 下 JSZip 会产出非合规包（详见 [pptxgenjs.md](pptxgenjs.md) 文首铁律）。
>
> **用了 SVG 配图的，合规校验前先跑 `node scripts/svg_fallback.mjs deck.pptx`**：PptxGenJS 在 Node 下
> 不栅格化 SVG 的 PNG 兜底（issue #401），不补的话下文 soffice 视觉 QA、旧版 PowerPoint、缩略图全破图。
> 该脚本顺带做合规重打包（等价 `--repack`）。详见 [svg.md](svg.md)。
>
> 内容/视觉 QA（下文）是合规之后的补充，不能替代合规校验。

### 第 6 项校验：Content_Types 孤儿 Override

`opc_check.py` 现包含 6 项校验。第 6 项专门捕获「`[Content_Types].xml` 声明了
zip 里不存在的 part」——OPC 规范允许这种「孤儿 Override」，python-pptx 也照常加载，
但 PowerPoint 严格对账「声明 vs 实物」时会把数量严重不符的包判损坏。

**典型症状**：PowerPoint 弹「找到无法读取的内容，是否要修复？」，
但 `python scripts/opc_check.py xxx.pptx` 报 PASSED（旧版 5 项会误判通过）。

**典型成因**：生成端把另一种 part 的数量当成这种 part 的数量，
例如 18 张 slide 却声明了 18 个 `slideMaster{n}.xml`，实际只有 1 个母版。
也见于「按模板复制后忘了同步删 Content_Types 行」。

**触发后修复**：直接运行 `python scripts/opc_check.py bad.pptx --repack fixed.pptx`。
`--repack` 会自动删除这些孤儿 `<Override>`，同时保留有效 Override、删除目录条目、
强制 DEFLATE 并把 `[Content_Types].xml` 放回 zip 首位。

### 布局/对比 确定性闸门（opc 之后、视觉 QA 之前）

```bash
python scripts/layout_lint.py deck.pptx
```

不依赖 soffice/截图，纯解析 slide XML，自动抓三类**可计算**的缺陷：

- **残桩/过短连线**（< 0.2"）——无连接的短箭头是 AI 生成 PPT 的典型痕迹。
- **形状叠加**——非背景、非包含的形状包围盒显著相交（内容互相压住）。
- **低对比文字**——形状显式填充色 vs 其文字显式色，大字 < 3:1 / 正文 < 4.5:1（看不清）。

退出码非 0 即有缺陷，按提示修。这是给**其他 agent / 弱模型**的防呆硬门槛——**不读文档也会被它拦下**。
它**不替代**下面的视觉 QA（主题色继承、跨形状 z-order 层叠、文字截断等仍需眼睛），但先把可计算的挡掉。

> 双保险：用 `scripts/deck_helpers.mjs` 的 `inkFor(bg)` / `assertReadable` / `connect(from,to)` 在
> **生成期**就避开这三类缺陷（源头预防），本闸门在产物上兜底（模型无关、绕不过）。

### Content QA

```bash
python -m markitdown output.pptx
```

Check for missing content, typos, wrong order.

**When using templates, check for leftover placeholder text:**

```bash
python -m markitdown output.pptx | grep -iE "xxxx|lorem|ipsum|this.*(page|slide).*layout"
```

If grep returns results, fix them before declaring success.

### Visual QA

**⚠️ USE SUBAGENTS** — even for 2-3 slides. You've been staring at the code and will see what you expect, not what's there. Subagents have fresh eyes.

Convert slides to images (see [Converting to Images](#converting-to-images)), then use this prompt:

```
Visually inspect these slides. Assume there are issues — find them.

Look for:
- Overlapping elements (text through shapes, lines through words, stacked elements)
- Text overflow or cut off at edges/box boundaries
- Decorative lines positioned for single-line text but title wrapped to two lines
- Source citations or footers colliding with content above
- Elements too close (< 0.3" gaps) or cards/sections nearly touching
- Uneven gaps (large empty area in one place, cramped in another)
- Insufficient margin from slide edges (< 0.5")
- Columns or similar elements not aligned consistently
- Low-contrast text (e.g., light gray text on cream-colored background)
- Low-contrast icons (e.g., dark icons on dark backgrounds without a contrasting circle)
- Text boxes too narrow causing excessive wrapping
- Leftover placeholder content

For each slide, list issues or areas of concern, even if minor.

Read and analyze these images:
1. /path/to/slide-01.jpg (Expected: [brief description])
2. /path/to/slide-02.jpg (Expected: [brief description])

Report ALL issues found, including minor ones.
```

### Verification Loop

1. Generate slides → Convert to images → Inspect
2. **List issues found** (if none found, look again more critically)
3. Fix issues
4. **Re-verify affected slides** — one fix often creates another problem
5. Repeat until a full pass reveals no new issues

**Do not declare success until you've completed at least one fix-and-verify cycle.**

---

## Converting to Images

Convert presentations to individual slide images for visual inspection:

```bash
python scripts/office/soffice.py --headless --convert-to pdf output.pptx
pdftoppm -jpeg -r 150 output.pdf slide
```

This creates `slide-01.jpg`, `slide-02.jpg`, etc.

To re-render specific slides after fixes:

```bash
pdftoppm -jpeg -r 150 -f N -l N output.pdf slide-fixed
```

---

## Dependencies

- `pip install "markitdown[pptx]"` - text extraction
- `pip install Pillow` - thumbnail grids
- `npm install -g pptxgenjs` - creating from scratch（**用 Node 运行，不要 `bun run`**）
- `npm install sharp` - SVG → PNG 兜底栅格化（`scripts/svg_fallback.mjs` 用；本仓库已装）
- `scripts/opc_check.py` - OPC 合规校验/重打包（仅依赖 Python 标准库，无需额外安装）
- `scripts/layout_lint.py` - 布局/对比 确定性闸门：残桩连线 / 形状叠加 / 低对比文字（仅依赖 Python 标准库）
- `scripts/svg_fallback.mjs` - SVG 配图兜底修复 + 合规重打包（Node + sharp + 调 opc_check.py）
- `scripts/deck_helpers.mjs` - 可复用原生 addShape 矢量原语（结构图路线）
- LibreOffice (`soffice`) - PDF conversion (auto-configured for sandboxed environments via `scripts/office/soffice.py`)
- Poppler (`pdftoppm`) - PDF to images
