| name | pptx |
| description | Create, modify, and analyze PowerPoint presentations (.pptx) using standard Python libraries. |
| license | Apache-2.0 |
PPTX Skill
This skill enables programmatic creation and modification of PowerPoint presentations (.pptx) using Python.
Core Capabilities
- Create New Presentations: Generate structured slide decks from templates or scratch.
- Modify Existing Decks: Update text, replace images, or add new slides to existing files.
- Read Content: Inspect slide layouts, shapes, and text content.
Dependencies
python-pptx (pip install python-pptx)
Pillow (pip install Pillow) for image handling
Workflows
1. Creating a New Presentation
from pptx import Presentation
from pptx.util import Inches
prs = Presentation()
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 = "Generated by python-pptx"
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('output.pptx')
2. Modifying an Existing Presentation
from pptx import Presentation
prs = Presentation('template.pptx')
if prs.slides[0].shapes.title:
prs.slides[0].shapes.title.text = "Updated Title"
img_path = 'image.png'
if len(prs.slides) > 1:
slide = prs.slides[1]
left = top = Inches(1)
slide.shapes.add_picture(img_path, left, top)
prs.save('modified.pptx')
3. Reading and Analyzing
from pptx import Presentation
prs = Presentation('input.pptx')
print(f"Total Slides: {len(prs.slides)}")
for i, slide in enumerate(prs.slides):
print(f"Slide {i+1} Shapes:")
for shape in slide.shapes:
if shape.has_text_frame:
print(f" - Text: {shape.text}")
Best Practices
- Templates: Use existing templates (
.pptx files) for complex layouts rather than creating shapes from scratch.
- Placeholders: Identify placeholders by index (
prs.slide_layouts[n]) or name.
- Images: Ensure images are available locally before insertion.