PPT Generator
Overview
Generate professional .pptx files using python-pptx. Accept input as natural language ("make a 10-slide deck about AI safety") or structured Markdown outlines.
Workflow
- Parse input — extract topic, slide count, style hints from user's natural language or Markdown outline
- Design outline — plan each slide: layout type, title, content summary
- Present outline to user — show a numbered slide list for confirmation before writing code
- Generate script — write a self-contained Python script using python-pptx
- Execute and verify — run the script, confirm the .pptx file was created
Never skip step 3. Always get user approval on the outline before writing code.
Typography Rules
These are mandatory defaults. Only deviate if the user explicitly overrides.
| Element | Font Size | Weight | Color |
|---|---|---|---|
| Slide title | 32pt | Bold | #1a1a2e |
| Subtitle | 18pt | Normal | #555555 |
| Body text | 14pt | Normal | #333333 |
| Small label | 11pt | Normal | #888888 |
Margins: left/right 1.5 inch, top/bottom 1.2 inch (when using manual text boxes). For built-in layouts, leave at defaults.
Color Themes
Four preset themes. Default is "Professional Blue". User can switch by name.
| Theme | Primary | Secondary | Accent | Background |
|---|---|---|---|---|
| Professional Blue | #1a1a2e | #16213e | #0f3460 | #ffffff |
| Warm Orange | #e07a5f | #3d405b | #81b29a | #f4f1de |
| Clean Green | #2d6a4f | #40916c | #52b788 | #ffffff |
| Dark Mode | #e0e0e0 | #bb86fc | #03dac6 | #121212 |
Slide Types
Title Slide
Centered title, subtitle, author/date. Use PPT_LAYOUT_TITLE (layout index 0).
Content Slide (Bullet List)
Title at top, bullet points in body. Use PPT_LAYOUT_BODY (layout index 1) or manual text box for multi-level lists.
Two-Column
Title, two text columns side by side. Use manual text boxes positioned at 0.5" and 5.0" horizontally.
Image + Text
Title, image on one side, text on the other. Use add_picture() with manual placement.
Table Slide
Title + table. Use add_table(rows, cols).
Ending Slide
Centered "Thank You" or "Q&A" with contact info. Same layout as title slide.
Code Patterns
Bootstrap every script like this:
from pptx import Presentation
from pptx.util import Inches, Pt, Emu
from pptx.dml.color import RGBColor
from pptx.enum.text import PP_ALIGN, MSO_ANCHOR
import os
prs = Presentation()
prs.slide_width = Inches(13.333) # 16:9 widescreen
prs.slide_height = Inches(7.5)
# Theme colors (Professional Blue)
PRIMARY = RGBColor(0x1a, 0x1a, 0x2e)
SECONDARY = RGBColor(0x16, 0x21, 0x3e)
ACCENT = RGBColor(0x0f, 0x34, 0x60)
BG = RGBColor(0xff, 0xff, 0xff)
# Helper: add a text box
def add_textbox(slide, left, top, width, height, text, font_size=Pt(14),
bold=False, color=RGBColor(0x33, 0x33, 0x33), alignment=PP_ALIGN.LEFT):
txBox = slide.shapes.add_textbox(Inches(left), Inches(top),
Inches(width), Inches(height))
tf = txBox.text_frame
tf.word_wrap = True
p = tf.paragraphs[0]
p.text = text
p.font.size = font_size
p.font.bold = bold
p.font.color.rgb = color
p.alignment = alignment
return tf
# Helper: add bullet points from a list
def add_bullet_list(slide, left, top, width, height, items, font_size=Pt(14)):
txBox = slide.shapes.add_textbox(Inches(left), Inches(top),
Inches(width), Inches(height))
tf = txBox.text_frame
tf.word_wrap = True
for i, item in enumerate(items):
if i == 0:
p = tf.paragraphs[0]
else:
p = tf.add_paragraph()
p.text = item
p.font.size = font_size
p.font.color.rgb = RGBColor(0x33, 0x33, 0x33)
p.level = 0
p.space_after = Pt(6)
return tf
Title slide:
slide = prs.slides.add_slide(prs.slide_layouts[6]) # blank layout
add_textbox(slide, 1.5, 2.0, 10, 1.5, "Presentation Title",
Pt(36), True, PRIMARY, PP_ALIGN.CENTER)
add_textbox(slide, 1.5, 3.5, 10, 0.8, "Subtitle or Author",
Pt(18), False, RGBColor(0x55, 0x55, 0x55), PP_ALIGN.CENTER)
add_textbox(slide, 1.5, 4.5, 10, 0.5, "2024-01-15",
Pt(11), False, RGBColor(0x88, 0x88, 0x88), PP_ALIGN.CENTER)
Content slide with bullets:
slide = prs.slides.add_slide(prs.slide_layouts[6])
add_textbox(slide, 0.8, 0.4, 10, 0.8, "Slide Title", Pt(32), True, PRIMARY)
items = ["Point one: key insight", "Point two: supporting detail", "Point three: takeaway"]
add_bullet_list(slide, 1.0, 1.5, 11, 4.5, items)
Save the file:
output_path = os.path.expanduser("~/Desktop/presentation.pptx")
prs.save(output_path)
print(f"Saved to {output_path}")
Input Formats
Natural Language
User says: "做一个关于时间管理的5页PPT"
→ Claude designs the outline, presents it, then generates.
Markdown Outline
User provides:
# 时间管理
## 1. 为什么需要时间管理
- 提高效率
- 减少压力
## 2. 四象限法则
- 重要紧急
- 重要不紧急
...
→ Claude maps each ## heading to a slide, each bullet to a list item, and generates.
Common Mistakes
| Mistake | Fix |
|---|---|
| Text overflowing slide | Break long text into multiple slides or reduce font size |
| Missing font file for Chinese | Always use a font that supports CJK (e.g., "Microsoft YaHei", "SimSun"). Add p.font.name = 'Microsoft YaHei' for Chinese text |
| Using wrong layout index | Layout 0 = title, 1 = content, 6 = blank. Check with prs.slide_layouts if unsure |
| Forgetting Inches/Pt wrappers | All dimensions must use Inches() or Pt() from pptx.util |
| Not setting word_wrap | Long text without word_wrap = True overflows horizontally |
Reference Files
reference/python-pptx-api.md— Full python-pptx API quick referencescripts/ppt_helpers.py— Ready-to-import helper functions for common slide patterns