PowerPoint Processing
Creating Presentations (Python)
from pptx import Presentation
from pptx.util import Inches, Pt
prs = Presentation()
# Add title slide
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Hello, World!"
subtitle.text = "python-pptx demo"
# Add content slide
bullet_slide_layout = prs.slide_layouts[1]
slide = prs.slides.add_slide(bullet_slide_layout)
shapes = slide.shapes
title_shape = shapes.title
body_shape = shapes.placeholders[1]
title_shape.text = "Key Points"
tf = body_shape.text_frame
tf.text = "First bullet point"
p = tf.add_paragraph()
p.text = "Second bullet point"
p.level = 1
prs.save('presentation.pptx')
Adding Images
from pptx.util import Inches
blank_layout = prs.slide_layouts[6]
slide = prs.slides.add_slide(blank_layout)
left = Inches(1)
top = Inches(1)
width = Inches(5)
slide.shapes.add_picture('image.png', left, top, width=width)
Adding Tables
rows, cols = 3, 4
left = Inches(1)
top = Inches(2)
width = Inches(6)
height = Inches(1.5)
table = slide.shapes.add_table(rows, cols, left, top, width, height).table
# Set column widths
table.columns[0].width = Inches(2)
# Add content
table.cell(0, 0).text = "Header 1"
table.cell(1, 0).text = "Data 1"
Adding Charts
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
chart_data = CategoryChartData()
chart_data.categories = ['East', 'West', 'Midwest']
chart_data.add_series('Sales', (19.2, 21.4, 16.7))
x, y, cx, cy = Inches(2), Inches(2), Inches(6), Inches(4.5)
slide.shapes.add_chart(
XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data
)
Editing Existing Presentations
prs = Presentation('existing.pptx')
# Access slides
for slide in prs.slides:
for shape in slide.shapes:
if shape.has_text_frame:
print(shape.text_frame.text)
# Modify text
slide = prs.slides[0]
slide.shapes.title.text = "New Title"
prs.save('modified.pptx')
Best Practices
- Use slide layouts for consistency
- Keep text minimal, use visuals
- Use Inches() or Pt() for sizing
- Save frequently during creation
Design & Aesthetics (Practical Rules)
Use these guidelines when generating or editing slides so the deck looks intentional, modern, and consistent.
Layout & Grid
- Prefer a simple grid (e.g., 12-column feel) and align everything to consistent left edges.
- Keep a single dominant focal point per slide (one headline + one visual or one chart).
- Use generous margins/whitespace. As a rule of thumb, keep key content inside ~10% padding from slide edges.
- Keep consistent spacing between elements (e.g., 8/16/24/32 px style steps). Avoid “almost equal” gaps.
Typography & Hierarchy
- Use 1 font family (or 2 at most: one for headings, one for body). Avoid mixing many fonts.
- Establish clear hierarchy:
- Title: ~36–44 pt
- Section header: ~28–34 pt
- Body: ~18–24 pt
- Caption/footnote: ~12–14 pt
- Keep line length comfortable; avoid long paragraphs. Prefer bullets with strong nouns/verbs.
- Use bold for emphasis, avoid underlines; italics only sparingly.
Color System
- Use a restrained palette:
- 1 primary accent color
- 1 neutral dark (text)
- 1 neutral light (background)
- Optional 1 secondary accent
- Maintain contrast: dark text on light background (or vice versa). Avoid low-contrast gray-on-gray.
- Use color to encode meaning consistently (e.g., success=green, risk=red) and keep it consistent across slides.
Visuals (Icons / Images / Shapes)
- Prefer high-quality visuals with consistent style (all flat icons, or all line icons—not mixed).
- Avoid stretching images; preserve aspect ratio and crop intentionally.
- Use subtle shape styling: thin strokes, soft shadows (if any), consistent corner radius.
- Avoid decorative clutter: every icon/shape should clarify structure or meaning.
Images / Illustration Direction
- Prefer one visual style per deck: photo-real, 3D renders, flat illustration, or line illustration. Don’t mix styles.
- Resolution: use sufficiently large images (avoid blurry screenshots). If an image will be full-width, it should be at least ~1920px wide.
- Cropping: crop for composition (rule of thirds, clear subject). Avoid awkward cut-offs (hands/heads) unless intentional.
- Backgrounds: prefer clean backgrounds; remove busy backgrounds when they distract. If needed, place images on a solid/blurred panel.
- Color & tone: keep color temperature and contrast consistent across slides; apply the same tint/duotone treatment if used.
- Text on images: ensure readability with overlay scrims/gradient, and keep contrast high. Avoid putting text over noisy areas.
- Icon usage: keep icon stroke weight and corner style consistent; avoid mixing filled and outline icons in the same row.
- Captions & sources: if the deck is external-facing, add a small caption/source line for non-original images.
- Licensing: use properly licensed assets; avoid random web images for public decks unless attribution/license is clear.
Charts & Tables
- Remove chart junk: minimize gridlines, borders, and unnecessary labels.
- Use one highlight color to direct attention; keep other series neutral.
- Prefer direct labels over legends when possible.
- Keep tables minimal: light row separators, consistent number formats, right-align numbers.
Consistency Checklist (Quick)
- Same title position across slides
- Same font sizes for same roles (title/body/caption)
- Same color usage for same semantics
- Same alignment rules (left edges, baseline alignment)
- No overlapping elements; equal spacing; no “almost aligned” objects
1---2name: pptx3description: Presentation creation, editing, and analysis. When Claude needs to work with presentations (.pptx files) for creating new presentations, modifying content, working with layouts, adding speaker notes, or any presentation tasks.4license: Apache-2.05---67# PowerPoint Processing89## Creating Presentations (Python)1011```python12from pptx import Presentation13from pptx.util import Inches, Pt1415prs = Presentation()1617# Add title slide18title_slide_layout = prs.slide_layouts[0]19slide = prs.slides.add_slide(title_slide_layout)20title = slide.shapes.title21subtitle = slide.placeholders[1]22title.text = "Hello, World!"23subtitle.text = "python-pptx demo"2425# Add content slide26bullet_slide_layout = prs.slide_layouts[1]27slide = prs.slides.add_slide(bullet_slide_layout)28shapes = slide.shapes29title_shape = shapes.title30body_shape = shapes.placeholders[1]31title_shape.text = "Key Points"32tf = body_shape.text_frame33tf.text = "First bullet point"34p = tf.add_paragraph()35p.text = "Second bullet point"36p.level = 13738prs.save('presentation.pptx')39```4041## Adding Images4243```python44from pptx.util import Inches4546blank_layout = prs.slide_layouts[6]47slide = prs.slides.add_slide(blank_layout)4849left = Inches(1)50top = Inches(1)51width = Inches(5)52slide.shapes.add_picture('image.png', left, top, width=width)53```5455## Adding Tables5657```python58rows, cols = 3, 459left = Inches(1)60top = Inches(2)61width = Inches(6)62height = Inches(1.5)6364table = slide.shapes.add_table(rows, cols, left, top, width, height).table6566# Set column widths67table.columns[0].width = Inches(2)6869# Add content70table.cell(0, 0).text = "Header 1"71table.cell(1, 0).text = "Data 1"72```7374## Adding Charts7576```python77from pptx.chart.data import CategoryChartData78from pptx.enum.chart import XL_CHART_TYPE7980chart_data = CategoryChartData()81chart_data.categories = ['East', 'West', 'Midwest']82chart_data.add_series('Sales', (19.2, 21.4, 16.7))8384x, y, cx, cy = Inches(2), Inches(2), Inches(6), Inches(4.5)85slide.shapes.add_chart(86 XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data87)88```8990## Editing Existing Presentations9192```python93prs = Presentation('existing.pptx')9495# Access slides96for slide in prs.slides:97 for shape in slide.shapes:98 if shape.has_text_frame:99 print(shape.text_frame.text)100101# Modify text102slide = prs.slides[0]103slide.shapes.title.text = "New Title"104105prs.save('modified.pptx')106```107108## Best Practices109110- Use slide layouts for consistency111- Keep text minimal, use visuals112- Use Inches() or Pt() for sizing113- Save frequently during creation114115## Design & Aesthetics (Practical Rules)116117Use these guidelines when generating or editing slides so the deck looks intentional, modern, and consistent.118119### Layout & Grid120121- Prefer a **simple grid** (e.g., 12-column feel) and align everything to consistent left edges.122- Keep a **single dominant focal point** per slide (one headline + one visual or one chart).123- Use generous **margins/whitespace**. As a rule of thumb, keep key content inside ~10% padding from slide edges.124- Keep **consistent spacing** between elements (e.g., 8/16/24/32 px style steps). Avoid “almost equal” gaps.125126### Typography & Hierarchy127128- Use **1 font family** (or 2 at most: one for headings, one for body). Avoid mixing many fonts.129- Establish clear hierarchy:130 - Title: ~36–44 pt131 - Section header: ~28–34 pt132 - Body: ~18–24 pt133 - Caption/footnote: ~12–14 pt134- Keep line length comfortable; avoid long paragraphs. Prefer **bullets with strong nouns/verbs**.135- Use bold for emphasis, avoid underlines; italics only sparingly.136137### Color System138139- Use a restrained palette:140 - 1 primary accent color141 - 1 neutral dark (text)142 - 1 neutral light (background)143 - Optional 1 secondary accent144- Maintain contrast: dark text on light background (or vice versa). Avoid low-contrast gray-on-gray.145- Use color to encode meaning consistently (e.g., success=green, risk=red) and keep it consistent across slides.146147### Visuals (Icons / Images / Shapes)148149- Prefer **high-quality visuals** with consistent style (all flat icons, or all line icons—not mixed).150- Avoid stretching images; preserve aspect ratio and crop intentionally.151- Use subtle shape styling: thin strokes, soft shadows (if any), consistent corner radius.152- Avoid decorative clutter: every icon/shape should clarify structure or meaning.153154### Images / Illustration Direction155156- Prefer **one visual style per deck**: photo-real, 3D renders, flat illustration, or line illustration. Don’t mix styles.157- **Resolution**: use sufficiently large images (avoid blurry screenshots). If an image will be full-width, it should be at least ~1920px wide.158- **Cropping**: crop for composition (rule of thirds, clear subject). Avoid awkward cut-offs (hands/heads) unless intentional.159- **Backgrounds**: prefer clean backgrounds; remove busy backgrounds when they distract. If needed, place images on a solid/blurred panel.160- **Color & tone**: keep color temperature and contrast consistent across slides; apply the same tint/duotone treatment if used.161- **Text on images**: ensure readability with overlay scrims/gradient, and keep contrast high. Avoid putting text over noisy areas.162- **Icon usage**: keep icon stroke weight and corner style consistent; avoid mixing filled and outline icons in the same row.163- **Captions & sources**: if the deck is external-facing, add a small caption/source line for non-original images.164- **Licensing**: use properly licensed assets; avoid random web images for public decks unless attribution/license is clear.165166### Charts & Tables167168- Remove chart junk: minimize gridlines, borders, and unnecessary labels.169- Use **one highlight color** to direct attention; keep other series neutral.170- Prefer direct labels over legends when possible.171- Keep tables minimal: light row separators, consistent number formats, right-align numbers.172173### Consistency Checklist (Quick)174175- Same title position across slides176- Same font sizes for same roles (title/body/caption)177- Same color usage for same semantics178- Same alignment rules (left edges, baseline alignment)179- No overlapping elements; equal spacing; no “almost aligned” objects