---
name: pptx
description: Create, read, and edit Microsoft PowerPoint (.pptx) presentations. Use when the user wants a slide deck / .pptx — pitch decks, summaries, reports as slides — or to edit an existing deck (add slides, text, tables, images, charts). Uses the open-source python-pptx library. Not for Word, Excel, or PDF.
---

# PowerPoint (.pptx) presentations

Build and edit `.pptx` files with the open-source **python-pptx** library. Run through Bash on absolute paths.

## Preflight — Python + the library (install on demand)
1. **Find Python.** `python3 --version`, else `python --version`. Use whichever works (`PY`).
2. **If neither exists, guide the user once** (in their language) — this needs a one-time Python install; then wait, don't fabricate:
   - macOS `brew install python` · Windows `winget install -e --id Python.Python.3.12` (or python.org, add to PATH) · Linux `sudo apt install -y python3 python3-pip`.
3. **Ensure python-pptx** (installs only if missing):
   ```bash
   PY -c "import pptx" 2>/dev/null || PY -m pip install --quiet --user python-pptx
   ```
   If pip is offline/blocked, say so and stop.

## Create a deck
Slides are built from **layouts** in the template's slide master; add content into the layout's **placeholders**.
```python
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.dml.color import RGBColor

prs = Presentation()                      # blank 4:3; or Presentation("template.pptx")
# Common layout indices in the default template:
#   0 Title, 1 Title+Content, 5 Title Only, 6 Blank
title_slide = prs.slides.add_slide(prs.slide_layouts[0])
title_slide.shapes.title.text = "Q4 Review"
title_slide.placeholders[1].text = "Prepared for the board"

body = prs.slides.add_slide(prs.slide_layouts[1])
body.shapes.title.text = "Highlights"
tf = body.placeholders[1].text_frame       # bullet body
tf.text = "Revenue up 18%"
for line in ["Churn down", "2 new markets"]:
    p = tf.add_paragraph(); p.text = line; p.level = 1

prs.save("/abs/path/out.pptx")
```

## Text, tables, images, charts
```python
from pptx.util import Inches, Pt
slide = prs.slides.add_slide(prs.slide_layouts[6])          # blank

# free text box
tb = slide.shapes.add_textbox(Inches(1), Inches(1), Inches(8), Inches(1))
r = tb.text_frame.paragraphs[0].add_run(); r.text = "Title"
r.font.size = Pt(28); r.font.bold = True; r.font.color.rgb = RGBColor(0x1F,0x4E,0x79)

# table
rows, cols = 3, 2
tbl = slide.shapes.add_table(rows, cols, Inches(1), Inches(2.5), Inches(6), Inches(2)).table
tbl.cell(0,0).text = "Metric"; tbl.cell(0,1).text = "Value"

slide.shapes.add_picture("/abs/path/chart.png", Inches(1), Inches(1), width=Inches(6))

from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
cd = CategoryChartData(); cd.categories = ["Jan","Feb","Mar"]; cd.add_series("Rev", (12,15,17))
slide.shapes.add_chart(XL_CHART_TYPE.COLUMN_CLUSTERED, Inches(1), Inches(1), Inches(6), Inches(4), cd)
```
Positions/sizes are EMU — always use `Inches(...)` / `Pt(...)`, never raw numbers.

## Edit an existing deck
`prs = Presentation("/abs/in.pptx")`, iterate `prs.slides` and `slide.shapes` (check `shape.has_text_frame`, `shape.has_table`), mutate, `save()`. Preserves the template's theme and untouched slides.

## Read / summarize
Iterate slides → shapes → `shape.text_frame.text` to pull the outline.

## Convert to PDF
`soffice --headless --convert-to pdf --outdir /abs/dir /abs/path/out.pptx` when LibreOffice is available.

## Conventions
- Reuse a provided `template.pptx` so brand theme/fonts carry over.
- Keep slides uncluttered (a few bullets each). Save to an absolute path and report it.
