pptx-generator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PPTX Generator

PPTX 生成工具

When to Use This Skill

何时使用此技能

Use this skill when:
  • Creating presentations programmatically from data or specifications
  • Populating branded templates with dynamic content while preserving corporate styling
  • Extracting text and structure from existing PPTX files for analysis
  • Combining slides from a library of approved templates
  • Automating presentation generation workflows
Do NOT use this skill when:
  • User wants to open/view presentations (use native PowerPoint or viewer)
  • Complex animations or transitions are required (limited support)
  • Working with older .ppt format (PPTX only)
在以下场景使用此技能:
  • 根据数据或规范以编程方式创建演示文稿
  • 为品牌化模板填充动态内容,同时保留企业样式
  • 从现有PPTX文件中提取文本和结构用于分析
  • 从已批准的模板库中组合幻灯片
  • 自动化演示文稿生成工作流
请勿在以下场景使用此技能:
  • 用户想要打开/查看演示文稿(使用原生PowerPoint或查看器)
  • 需要复杂动画或转场效果(仅支持基础功能)
  • 处理旧版.ppt格式(仅支持PPTX)

Prerequisites

前提条件

  • Deno installed (https://deno.land/)
  • Input PPTX files for template-based operations
  • JSON specification for scratch generation
  • 已安装Deno(https://deno.land/)
  • 用于模板化操作的输入PPTX文件
  • 用于从零开始创建的JSON规范

Quick Start

快速开始

Two Modes of Operation

两种操作模式

  1. Template Mode: Modify existing branded templates
    • Analyze & Replace: Find
      {{PLACEHOLDERS}}
      and replace with content
    • Slide Library: Select and combine slides from a template library
  2. Scratch Mode: Create presentations from nothing using JSON specifications
  1. 模板模式:修改现有品牌化模板
    • 分析与替换:查找
      {{PLACEHOLDERS}}
      并替换为内容
    • 幻灯片库:从模板库中选择并组合幻灯片
  2. 从零创建模式:使用JSON规范从头创建演示文稿

Instructions

操作说明

Mode 1: Template-Based Generation

模式1:基于模板的生成

Step 1a: Analyze the Template

步骤1a:分析模板

Extract text inventory to understand what can be replaced:
bash
deno run --allow-read scripts/analyze-template.ts corporate-template.pptx > inventory.json
Output (inventory.json):
json
{
  "filename": "corporate-template.pptx",
  "slideCount": 10,
  "textElements": [
    {
      "slideNumber": 1,
      "shapeId": "shape-2",
      "shapeName": "Title 1",
      "placeholderType": "ctrTitle",
      "position": { "x": 1.5, "y": 2.0, "w": 7.0, "h": 1.2 },
      "paragraphs": [
        { "text": "{{TITLE}}", "fontSize": 44, "bold": true }
      ]
    }
  ]
}
提取文本清单以了解可替换内容:
bash
deno run --allow-read scripts/analyze-template.ts corporate-template.pptx > inventory.json
输出(inventory.json):
json
{
  "filename": "corporate-template.pptx",
  "slideCount": 10,
  "textElements": [
    {
      "slideNumber": 1,
      "shapeId": "shape-2",
      "shapeName": "Title 1",
      "placeholderType": "ctrTitle",
      "position": { "x": 1.5, "y": 2.0, "w": 7.0, "h": 1.2 },
      "paragraphs": [
        { "text": "{{TITLE}}", "fontSize": 44, "bold": true }
      ]
    }
  ]
}

Step 1b: Create Replacement Specification

步骤1b:创建替换规范

Create
replacements.json
:
json
{
  "textReplacements": [
    { "tag": "{{TITLE}}", "value": "Q4 2024 Results" },
    { "tag": "{{SUBTITLE}}", "value": "Financial Overview" },
    { "tag": "{{DATE}}", "value": "December 2024" },
    { "tag": "{{AUTHOR}}", "value": "Finance Team", "slideNumbers": [1] }
  ]
}
创建
replacements.json
json
{
  "textReplacements": [
    { "tag": "{{TITLE}}", "value": "Q4 2024 Results" },
    { "tag": "{{SUBTITLE}}", "value": "Financial Overview" },
    { "tag": "{{DATE}}", "value": "December 2024" },
    { "tag": "{{AUTHOR}}", "value": "Finance Team", "slideNumbers": [1] }
  ]
}

Step 1c: Generate Output

步骤1c:生成输出文件

bash
deno run --allow-read --allow-write scripts/generate-from-template.ts \
  corporate-template.pptx replacements.json output.pptx
bash
deno run --allow-read --allow-write scripts/generate-from-template.ts \
  corporate-template.pptx replacements.json output.pptx

Mode 1 (Alternative): Slide Library

模式1(替代方案):幻灯片库

Step 2a: Preview Template Slides

步骤2a:预览模板幻灯片

Get information about available slides:
bash
deno run --allow-read scripts/generate-thumbnails.ts slide-library.pptx
For visual preview, extract the thumbnail:
bash
deno run --allow-read --allow-write scripts/generate-thumbnails.ts \
  slide-library.pptx --extract-thumb --output-dir ./previews
获取可用幻灯片的信息:
bash
deno run --allow-read scripts/generate-thumbnails.ts slide-library.pptx
如需可视化预览,提取缩略图:
bash
deno run --allow-read --allow-write scripts/generate-thumbnails.ts \
  slide-library.pptx --extract-thumb --output-dir ./previews

Step 2b: Select and Combine Slides

步骤2b:选择并组合幻灯片

Create
selections.json
:
json
{
  "slideSelections": [
    { "slideNumber": 1 },
    { "slideNumber": 5 },
    { "slideNumber": 12 },
    { "slideNumber": 3 }
  ],
  "textReplacements": [
    { "tag": "{{TITLE}}", "value": "Custom Presentation" }
  ]
}
创建
selections.json
json
{
  "slideSelections": [
    { "slideNumber": 1 },
    { "slideNumber": 5 },
    { "slideNumber": 12 },
    { "slideNumber": 3 }
  ],
  "textReplacements": [
    { "tag": "{{TITLE}}", "value": "Custom Presentation" }
  ]
}

Step 2c: Generate Combined Presentation

步骤2c:生成组合演示文稿

bash
deno run --allow-read --allow-write scripts/generate-from-template.ts \
  slide-library.pptx selections.json custom-deck.pptx
bash
deno run --allow-read --allow-write scripts/generate-from-template.ts \
  slide-library.pptx selections.json custom-deck.pptx

Mode 2: From-Scratch Generation

模式2:从零开始创建

Step 3a: Create Specification

步骤3a:创建规范文件

Create
spec.json
:
json
{
  "title": "Product Launch 2025",
  "author": "Marketing Team",
  "slides": [
    {
      "background": { "color": "003366" },
      "elements": [
        {
          "type": "text",
          "x": 1, "y": 2.5, "w": 8, "h": 1.5,
          "options": {
            "text": "Product Launch 2025",
            "fontSize": 44,
            "bold": true,
            "color": "FFFFFF",
            "align": "center"
          }
        },
        {
          "type": "text",
          "x": 1, "y": 4, "w": 8, "h": 0.5,
          "options": {
            "text": "Revolutionizing the Industry",
            "fontSize": 24,
            "color": "CCCCCC",
            "align": "center"
          }
        }
      ]
    },
    {
      "elements": [
        {
          "type": "text",
          "x": 0.5, "y": 0.5, "w": 9, "h": 0.7,
          "options": {
            "text": "Key Features",
            "fontSize": 32,
            "bold": true,
            "color": "003366"
          }
        },
        {
          "type": "table",
          "x": 0.5, "y": 1.5, "w": 9, "h": 3,
          "options": {
            "rows": [
              ["Feature", "Description", "Benefit"],
              ["Speed", "2x faster processing", "Save time"],
              ["Quality", "HD output", "Better results"],
              ["Integration", "Works with existing tools", "Easy adoption"]
            ],
            "border": { "pt": 1, "color": "CCCCCC" }
          }
        }
      ]
    }
  ]
}
创建
spec.json
json
{
  "title": "Product Launch 2025",
  "author": "Marketing Team",
  "slides": [
    {
      "background": { "color": "003366" },
      "elements": [
        {
          "type": "text",
          "x": 1, "y": 2.5, "w": 8, "h": 1.5,
          "options": {
            "text": "Product Launch 2025",
            "fontSize": 44,
            "bold": true,
            "color": "FFFFFF",
            "align": "center"
          }
        },
        {
          "type": "text",
          "x": 1, "y": 4, "w": 8, "h": 0.5,
          "options": {
            "text": "Revolutionizing the Industry",
            "fontSize": 24,
            "color": "CCCCCC",
            "align": "center"
          }
        }
      ]
    },
    {
      "elements": [
        {
          "type": "text",
          "x": 0.5, "y": 0.5, "w": 9, "h": 0.7,
          "options": {
            "text": "Key Features",
            "fontSize": 32,
            "bold": true,
            "color": "003366"
          }
        },
        {
          "type": "table",
          "x": 0.5, "y": 1.5, "w": 9, "h": 3,
          "options": {
            "rows": [
              ["Feature", "Description", "Benefit"],
              ["Speed", "2x faster processing", "Save time"],
              ["Quality", "HD output", "Better results"],
              ["Integration", "Works with existing tools", "Easy adoption"]
            ],
            "border": { "pt": 1, "color": "CCCCCC" }
          }
        }
      ]
    }
  ]
}

Step 3b: Generate Presentation

步骤3b:生成演示文稿

bash
deno run --allow-read --allow-write scripts/generate-scratch.ts spec.json output.pptx
bash
deno run --allow-read --allow-write scripts/generate-scratch.ts spec.json output.pptx

Examples

示例

Example 1: Corporate Quarterly Report

示例1:企业季度报告

Scenario: Generate quarterly report from branded template.
Steps:
bash
undefined
场景:从品牌化模板生成季度报告。
步骤
bash
undefined

1. Analyze template for replaceable content

1. 分析模板中的可替换内容

deno run --allow-read scripts/analyze-template.ts quarterly-template.pptx --pretty
deno run --allow-read scripts/analyze-template.ts quarterly-template.pptx --pretty

2. Create replacements.json with Q4 data

2. 创建包含Q4数据的replacements.json

3. Generate report

3. 生成报告

deno run --allow-read --allow-write scripts/generate-from-template.ts
quarterly-template.pptx replacements.json Q4-2024-Report.pptx
undefined
deno run --allow-read --allow-write scripts/generate-from-template.ts
quarterly-template.pptx replacements.json Q4-2024-Report.pptx
undefined

Example 2: Custom Pitch Deck from Slide Library

示例2:从幻灯片库创建自定义推介演示文稿

Scenario: Combine approved slides for a specific client pitch.
Steps:
bash
undefined
场景:为特定客户组合已批准的幻灯片。
步骤
bash
undefined

1. View available slides

1. 查看可用幻灯片

deno run --allow-read scripts/generate-thumbnails.ts pitch-library.pptx
deno run --allow-read scripts/generate-thumbnails.ts pitch-library.pptx

2. Create selections.json picking slides 1, 3, 7, 12, 15

2. 创建selections.json,选择幻灯片1、3、7、12、15

3. Generate custom deck

3. 生成自定义演示文稿

deno run --allow-read --allow-write scripts/generate-from-template.ts
pitch-library.pptx selections.json acme-pitch.pptx
undefined
deno run --allow-read --allow-write scripts/generate-from-template.ts
pitch-library.pptx selections.json acme-pitch.pptx
undefined

Example 3: Data-Driven Presentation

示例3:数据驱动的演示文稿

Scenario: Generate presentation from JSON data (e.g., API response).
Steps:
bash
undefined
场景:从JSON数据(如API响应)生成演示文稿。
步骤
bash
undefined

1. Transform your data into spec.json format

1. 将你的数据转换为spec.json格式

2. Generate presentation

2. 生成演示文稿

deno run --allow-read --allow-write scripts/generate-scratch.ts data-spec.json report.pptx
undefined
deno run --allow-read --allow-write scripts/generate-scratch.ts data-spec.json report.pptx
undefined

Script Reference

脚本参考

ScriptPurposePermissions
analyze-template.ts
Extract text inventory from PPTX
--allow-read
generate-thumbnails.ts
Get slide info and extract previews
--allow-read --allow-write
generate-from-template.ts
Modify templates (replace/combine)
--allow-read --allow-write
generate-scratch.ts
Create PPTX from JSON specification
--allow-read --allow-write
脚本用途权限
analyze-template.ts
从PPTX中提取文本清单
--allow-read
generate-thumbnails.ts
获取幻灯片信息并提取预览图
--allow-read --allow-write
generate-from-template.ts
修改模板(替换/组合)
--allow-read --allow-write
generate-scratch.ts
从JSON规范创建PPTX
--allow-read --allow-write

Element Types (Scratch Mode)

元素类型(从零创建模式)

TypeDescriptionKey Options
text
Text box
text
,
fontSize
,
bold
,
color
,
align
image
Image from file or base64
path
,
data
,
sizing
table
Data table
rows
,
colW
,
border
,
fill
shape
Geometric shapes
type
,
fill
,
line
,
text
chart
Charts and graphs
type
,
data
,
title
,
showLegend
类型描述关键选项
text
文本框
text
,
fontSize
,
bold
,
color
,
align
image
来自文件或base64的图片
path
,
data
,
sizing
table
数据表
rows
,
colW
,
border
,
fill
shape
几何形状
type
,
fill
,
line
,
text
chart
图表和图形
type
,
data
,
title
,
showLegend

Common Issues and Solutions

常见问题与解决方案

Issue: Text not being replaced

问题:文本未被替换

Symptoms: Output PPTX still contains
{{PLACEHOLDER}}
tags.
Solution:
  1. Run
    analyze-template.ts
    to verify exact tag text
  2. Tags may be split across XML runs - ensure your template has tags in single text runs
  3. Check
    slideNumbers
    filter in replacements
症状:输出的PPTX仍包含
{{PLACEHOLDER}}
标签。
解决方案
  1. 运行
    analyze-template.ts
    验证标签的准确文本
  2. 标签可能被拆分到XML运行段中 - 确保模板中的标签位于单个文本运行段内
  3. 检查替换内容中的
    slideNumbers
    过滤器

Issue: Slide order incorrect

问题:幻灯片顺序错误

Symptoms: Slides appear in wrong order after combining.
Solution:
  • Slides are added in the order specified in
    slideSelections
  • Verify slide numbers match original template (1-indexed)
症状:组合后幻灯片顺序不正确。
解决方案
  • 幻灯片会按照
    slideSelections
    中指定的顺序添加
  • 验证幻灯片编号与原始模板匹配(从1开始索引)

Issue: Images not appearing

问题:图片未显示

Symptoms: Image elements are blank in output.
Solution:
  1. Use absolute paths or paths relative to spec.json location
  2. Verify image file exists and is readable
  3. Check supported formats: PNG, JPEG, GIF
症状:输出中的图片元素为空。
解决方案
  1. 使用绝对路径或相对于spec.json位置的相对路径
  2. 验证图片文件存在且可读取
  3. 检查支持的格式:PNG、JPEG、GIF

OOXML Placeholder Inheritance (Advanced)

OOXML占位符继承(高级内容)

Understanding how PowerPoint's OOXML format handles placeholders is crucial for template development.
了解PowerPoint的OOXML格式如何处理占位符对于模板开发至关重要。

The Inheritance Chain

继承链

PowerPoint uses a hierarchical inheritance model:
Theme → Slide Master → Slide Layout → Slide
  • Theme: Defines colors, fonts, effects
  • Slide Master: Defines default placeholder positions and formatting (including bullets)
  • Slide Layout: Overrides master settings for specific layout types (e.g., Title Slide, Content)
  • Slide: Contains actual content, inherits formatting from layout
PowerPoint使用分层继承模型:
主题 → 幻灯片母版 → 幻灯片版式 → 幻灯片
  • 主题:定义颜色、字体、效果
  • 幻灯片母版:定义占位符的默认位置和格式(包括项目符号)
  • 幻灯片版式:为特定版式类型(如标题幻灯片、内容幻灯片)覆盖母版设置
  • 幻灯片:包含实际内容,从版式继承格式

Key Principles

核心原则

  1. Text Content Does NOT Inherit: Slides must contain their own text content. The
    {{placeholder}}
    text in a layout does NOT automatically appear on slides using that layout.
  2. Text Formatting CAN Inherit: When a slide shape has an empty
    <a:lstStyle/>
    , it inherits formatting (color, size, bullets) from the layout's
    <a:lstStyle>
    .
  3. Placeholder Linking: Slides link to layouts via
    <p:ph type="..." idx="..."/>
    . The
    type
    (e.g., "title", "body", "ctrTitle") and
    idx
    must match.
  4. Bullet Suppression: To prevent bullets on a placeholder that would normally inherit them from the master's bodyStyle, add
    <a:buNone/>
    in the layout's lstStyle.
  1. 文本内容不继承:幻灯片必须包含自己的文本内容。版式中的
    {{placeholder}}
    文本不会自动显示在使用该版式的幻灯片上。
  2. 文本格式可继承:当幻灯片形状包含空的
    <a:lstStyle/>
    时,它会从版式的
    <a:lstStyle>
    继承格式(颜色、大小、项目符号)。
  3. 占位符链接:幻灯片通过
    <p:ph type="..." idx="..."/>
    链接到版式。
    type
    (如"title"、"body"、"ctrTitle")和
    idx
    必须匹配。
  4. 项目符号抑制:若要防止占位符从母版的bodyStyle继承项目符号,可在版式的lstStyle中添加
    <a:buNone/>

Defining Inheritable Formatting

定义可继承格式

In layout placeholders, define colors in
<a:lstStyle>
(inheritable), not in
<a:rPr>
(run-specific):
xml
<!-- Layout: Color in lstStyle (GOOD - inheritable) -->
<p:txBody>
  <a:lstStyle>
    <a:lvl1pPr algn="ctr">
      <a:buNone/>  <!-- Suppress bullets -->
      <a:defRPr sz="4400" b="1">
        <a:solidFill><a:srgbClr val="FFFFFF"/></a:solidFill>
      </a:defRPr>
    </a:lvl1pPr>
  </a:lstStyle>
  <a:p>
    <a:r><a:rPr lang="en-US"/><a:t>{{placeholder}}</a:t></a:r>
  </a:p>
</p:txBody>
在版式占位符中,在
<a:lstStyle>
中定义颜色(可继承),而非在
<a:rPr>
中(运行段特定):
xml
<!-- 版式:在lstStyle中定义颜色(推荐 - 可继承) -->
<p:txBody>
  <a:lstStyle>
    <a:lvl1pPr algn="ctr">
      <a:buNone/>  <!-- 抑制项目符号 -->
      <a:defRPr sz="4400" b="1">
        <a:solidFill><a:srgbClr val="FFFFFF"/></a:solidFill>
      </a:defRPr>
    </a:lvl1pPr>
  </a:lstStyle>
  <a:p>
    <a:r><a:rPr lang="en-US"/><a:t>{{placeholder}}</a:t></a:r>
  </a:p>
</p:txBody>

Slide Shape Structure

幻灯片形状结构

For slides to properly inherit from layouts:
xml
<!-- Slide: Empty lstStyle to inherit from layout -->
<p:sp>
  <p:nvSpPr>
    <p:cNvPr id="2" name="title 2"/>
    <p:cNvSpPr><a:spLocks noGrp="1"/></p:cNvSpPr>
    <p:nvPr>
      <p:ph type="ctrTitle"/>  <!-- Links to layout placeholder -->
    </p:nvPr>
  </p:nvSpPr>
  <p:spPr/>  <!-- Empty = inherit position from layout -->
  <p:txBody>
    <a:bodyPr/>
    <a:lstStyle/>  <!-- Empty = inherit formatting from layout -->
    <a:p>
      <a:r>
        <a:rPr lang="en-US"/>  <!-- Empty = inherit character formatting -->
        <a:t>{{placeholder}}</a:t>  <!-- Content must be here -->
      </a:r>
    </a:p>
  </p:txBody>
</p:sp>
为使幻灯片正确从版式继承格式:
xml
<!-- 幻灯片:空lstStyle以从版式继承 -->
<p:sp>
  <p:nvSpPr>
    <p:cNvPr id="2" name="title 2"/>
    <p:cNvSpPr><a:spLocks noGrp="1"/></p:cNvSpPr>
    <p:nvPr>
      <p:ph type="ctrTitle"/>  <!-- 链接到版式占位符 -->
    </p:nvPr>
  </p:nvSpPr>
  <p:spPr/>  <!-- 空值 = 从版式继承位置 -->
  <p:txBody>
    <a:bodyPr/>
    <a:lstStyle/>  <!-- 空值 = 从版式继承格式 -->
    <a:p>
      <a:r>
        <a:rPr lang="en-US"/>  <!-- 空值 = 继承字符格式 -->
        <a:t>{{placeholder}}</a:t>  <!-- 内容必须在此处 -->
      </a:r>
    </a:p>
  </p:txBody>
</p:sp>

Common Issues

常见问题

IssueCauseSolution
Text shows as black instead of whiteColor defined in
<a:rPr>
not
<a:lstStyle>
Move color to layout's
<a:defRPr>
in
<a:lstStyle>
Unwanted bullets appearingMaster's bodyStyle has bullets, layout doesn't overrideAdd
<a:buNone/>
to layout's
<a:lvl1pPr>
Placeholder text not appearingText only in layout, not in slideInclude text content in slide's
<p:txBody>
Formatting not applyingSlide has explicit formattingUse empty
<a:lstStyle/>
and
<a:rPr lang="en-US"/>
问题原因解决方案
文本显示为黑色而非白色颜色定义在
<a:rPr>
中而非
<a:lstStyle>
将颜色移至版式
<a:lstStyle>
中的
<a:defRPr>
出现不需要的项目符号母版的bodyStyle包含项目符号,版式未覆盖在版式的
<a:lvl1pPr>
中添加
<a:buNone/>
占位符文本未显示文本仅存在于版式中,未在幻灯片中在幻灯片的
<p:txBody>
中包含文本内容
格式未应用幻灯片包含显式格式使用空的
<a:lstStyle/>
<a:rPr lang="en-US"/>

Reference: Placeholder Types

参考:占位符类型

TypeUsage
ctrTitle
Centered title (title slides)
title
Standard title
subTitle
Subtitle
body
Content area (use
idx
for multiple)
pic
Picture placeholder
dt
Date/time
ftr
Footer
sldNum
Slide number
类型用途
ctrTitle
居中标题(标题幻灯片)
title
标准标题
subTitle
副标题
body
内容区域(多个时使用
idx
pic
图片占位符
dt
日期/时间
ftr
页脚
sldNum
幻灯片编号

Limitations

局限性

  • No slide rendering: Cannot render slides to images directly (use LibreOffice for this)
  • Limited animation support: Basic animations only in scratch mode
  • No master slide editing: Template mode preserves but doesn't modify masters
  • PPTX only: Does not support legacy .ppt format
  • Text run splitting: Complex formatting in templates may split tags across XML elements
  • 无幻灯片渲染:无法直接将幻灯片渲染为图片(可使用LibreOffice完成此操作)
  • 有限的动画支持:从零创建模式仅支持基础动画
  • 无法编辑母版幻灯片:模板模式保留但不修改母版
  • 仅支持PPTX:不支持旧版.ppt格式
  • 文本运行段拆分:模板中的复杂格式可能将标签拆分到多个XML元素中

Related Skills

相关技能

  • pdf-generator: For creating PDF documents instead of presentations
  • docx-generator: For creating Word documents
  • xlsx-generator: For creating Excel spreadsheets
  • pdf-generator:用于创建PDF文档而非演示文稿
  • docx-generator:用于创建Word文档
  • xlsx-generator:用于创建Excel电子表格