PPTX - PowerPoint Presentations
Read, generate, and adjust slides, layouts, and templates for PowerPoint presentations programmatically.
npx degit LangbaseInc/agent-skills/document-skills/pptx my-pptx-skill
Create, modify, and analyze PowerPoint presentations (.pptx) programmatically for automation and customization.
Slide Management
- Create new presentations
- Add/delete slides
- Reorder slides
- Clone slides
- Apply layouts
Content Addition
- Add text boxes
- Insert images
- Add tables
- Insert charts
- Add shapes
- Embed videos
Formatting
- Text formatting (font, size, color)
- Shape formatting
- Slide backgrounds
- Color schemes
- Master slides
- Themes and layouts
Advanced Features
- Speaker notes
- Slide transitions
- Animations
- Hyperlinks
- Comments
- Metadata
Python
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.enum.shapes import MSO_SHAPE
# Create presentation
prs = Presentation()
# Add slide
slide_layout = prs.slide_layouts[0] # Title slide
slide = prs.slides.add_slide(slide_layout)
# Add title
title = slide.shapes.title
title.text = "Presentation Title"
# Add content
left = Inches(1)
top = Inches(2)
width = Inches(6)
height = Inches(1)
textbox = slide.shapes.add_textbox(left, top, width, height)
textbox.text = "This is a text box"
# Save
prs.save('presentation.pptx')
from pptx import Presentation
from pptx.util import Inches
prs = Presentation()
# Different slide layouts
title_slide_layout = prs.slide_layouts[0]
bullet_slide_layout = prs.slide_layouts[1]
blank_slide_layout = prs.slide_layouts[6]
# Add title slide
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Hello, World!"
subtitle.text = "Python-pptx presentation"
# Add bullet slide
slide = prs.slides.add_slide(bullet_slide_layout)
shapes = slide.shapes
title_shape = shapes.title
body_shape = shapes.placeholders[1]
title_shape.text = 'Adding a Bullet Slide'
tf = body_shape.text_frame
tf.text = 'First bullet'
# Add more bullets
p = tf.add_paragraph()
p.text = 'Second bullet'
p.level = 0
p = tf.add_paragraph()
p.text = 'Sub-bullet'
p.level = 1
from pptx import Presentation
from pptx.util import Inches
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[6])
# Add image
img_path = 'image.png'
left = Inches(1)
top = Inches(1)
width = Inches(4)
pic = slide.shapes.add_picture(img_path, left, top, width=width)
# Auto-fit maintaining aspect ratio
pic = slide.shapes.add_picture(img_path, left, top)
from pptx import Presentation
from pptx.util import Inches
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[6])
# Define table dimensions
rows, cols = 3, 3
left = Inches(2)
top = Inches(2)
width = Inches(6)
height = Inches(0.8)
# Add table
table = slide.shapes.add_table(rows, cols, left, top, width, height).table
# Set column widths
table.columns[0].width = Inches(2)
# Populate table
table.cell(0, 0).text = 'Header 1'
table.cell(0, 1).text = 'Header 2'
table.cell(0, 2).text = 'Header 3'
for row in range(1, rows):
for col in range(cols):
table.cell(row, col).text = f'Cell {row},{col}'
from pptx import Presentation
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
from pptx.util import Inches
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[6])
# Define chart data
chart_data = CategoryChartData()
chart_data.categories = ['Q1', 'Q2', 'Q3', 'Q4']
chart_data.add_series('Revenue', (100, 150, 120, 180))
# Add chart
x, y, cx, cy = Inches(2), Inches(2), Inches(6), Inches(4)
chart = slide.shapes.add_chart(
XL_CHART_TYPE.COLUMN_CLUSTERED,
x, y, cx, cy,
chart_data
).chart
chart.has_legend = True
chart.chart_title.text_frame.text = 'Quarterly Revenue'
from pptx import Presentation
from pptx.util import Pt
from pptx.dml.color import RGBColor
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[6])
textbox = slide.shapes.add_textbox(Inches(1), Inches(1), Inches(5), Inches(1))
tf = textbox.text_frame
p = tf.add_paragraph()
run = p.add_run()
run.text = "Formatted Text"
# Font formatting
font = run.font
font.name = 'Calibri'
font.size = Pt(24)
font.bold = True
font.italic = True
font.color.rgb = RGBColor(255, 0, 0)
from pptx import Presentation
from pptx.enum.shapes import MSO_SHAPE
from pptx.util import Inches
from pptx.dml.color import RGBColor
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[6])
# Add shape
left, top, width, height = Inches(1), Inches(1), Inches(2), Inches(1)
shape = slide.shapes.add_shape(
MSO_SHAPE.ROUNDED_RECTANGLE,
left, top, width, height
)
# Format shape
shape.fill.solid()
shape.fill.fore_color.rgb = RGBColor(0, 100, 200)
shape.line.color.rgb = RGBColor(255, 255, 255)
shape.line.width = Pt(2)
# Add text to shape
text_frame = shape.text_frame
text_frame.text = "Shape Text"
from pptx import Presentation
prs = Presentation('existing.pptx')
# Iterate through slides
for slide in prs.slides:
print(f"Slide {slide.slide_id}")
# Get all text
for shape in slide.shapes:
if hasattr(shape, "text"):
print(shape.text)
# Get images
for shape in slide.shapes:
if shape.shape_type == 13: # Picture
image = shape.image
print(f"Image: {image.filename}")
from pptx import Presentation
# Use template
template = Presentation('template.pptx')
slide = template.slides.add_slide(template.slide_layouts[0])
# Copy slides from another presentation
source = Presentation('source.pptx')
for slide in source.slides:
# Note: Copying slides requires custom implementation
pass
from pptx import Presentation
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[0])
# Add speaker notes
notes_slide = slide.notes_slide
text_frame = notes_slide.notes_text_frame
text_frame.text = "These are speaker notes"
- Automated report generation
- Data visualization
- Training materials
- Sales presentations
- Template customization
- Batch processing
- Dynamic content updates
- Use templates for consistency
- Optimize images before inserting
- Keep file sizes reasonable
- Test across PowerPoint versions
- Use appropriate layouts
- Maintain aspect ratios
- Document custom themes
- Version control templates