PPTX creation, editing, and analysis
Overview
Create, edit, or analyze the contents of .pptx files when requested. A .pptx file is essentially a ZIP archive containing XML files and other resources. Different tools and workflows are available for different tasks.
Reading and analyzing content
Text extraction
To read just the text content of a presentation, convert the document to markdown:
# Convert document to markdown
python -m markitdown path-to-file.pptx
Raw XML access
Use raw XML access for: comments, speaker notes, slide layouts, animations, design elements, and complex formatting. To access these features, unpack a presentation and read its raw XML contents.
Unpacking a file
python /mnt/skills/public/pptx/ooxml/scripts/unpack.py <office_file> <output_dir>
Key file structures
ppt/presentation.xml - Main presentation metadata and slide references
ppt/slides/slide{N}.xml - Individual slide contents (slide1.xml, slide2.xml, etc.)
ppt/notesSlides/notesSlide{N}.xml - Speaker notes for each slide
ppt/comments/modernComment_*.xml - Comments for specific slides
ppt/slideLayouts/ - Layout templates for slides
ppt/slideMasters/ - Master slide templates
ppt/theme/ - Theme and styling information
ppt/media/ - Images and other media files
Typography and color extraction
To emulate example designs, analyze the presentation's typography and colors first using the methods below:
- Read theme file: Check
ppt/theme/theme1.xml for colors (<a:clrScheme>) and fonts (<a:fontScheme>)
- Sample slide content: Examine
ppt/slides/slide1.xml for actual font usage (<a:rPr>) and colors
- Search for patterns: Use grep to find color (
<a:solidFill>, <a:srgbClr>) and font references across all XML files
Creating a new PowerPoint presentation without a template
When creating a new PowerPoint presentation from scratch, use the html2pptx workflow to convert HTML slides to PowerPoint with accurate positioning.
IMPORTANT: html2pptx is a JavaScript LIBRARY, not a CLI tool. You MUST create a .js script with import { html2pptx } and run it with node script.js. Do NOT run html2pptx, npx html2pptx, or create config.json files — html2pptx has no CLI interface.
Workflow
MANDATORY - READ ENTIRE FILE NOW: Read html2pptx.md completely from start to finish. NEVER set any range limits when reading this file. Read the full file content for detailed syntax, critical formatting rules, and best practices before proceeding with presentation creation.
PREREQUISITE - Install html2pptx library:
- Check and install if needed:
npm list -g @ant/html2pptx || npm install -g skills/pptx/html2pptx.tgz
- Note: If you see "Cannot find module '@ant/html2pptx'" error later, the package isn't installed
CRITICAL: Plan the presentation
- Plan the shared aspects of the presentation. Describe the tone of the presentation's content and the colors and typography that should be used in the presentation.
- Write a DETAILED outline of the presentation
- For each slide, describe the slide's layout and contents
- For each slide, write presenter notes (1 to 3 sentences per slide)
CRITICAL: Set CSS variables
- In a shared
.css file, override CSS variables to use on each slide for colors, typography, and spacing. DO NOT create classes in this file.
Create an HTML file for each slide with proper dimensions (e.g., 960px × 540px for 16:9)
- Recall the outline, layout/content description, and speaker notes you wrote for this slide in Step 3. Think out loud how to best apply them to this slide.
- Embed the contents of the shared
.css file in a <style> element
- Use
<p>, <h1>-<h6>, <ul>, <ol> for all text content
- IMPORTANT: Use CSS variables for colors, typography, and spacing
- IMPORTANT: Use
row col and fit classes for layout INSTEAD OF flexbox
- Use
class="placeholder" for areas where charts/tables will be added (render with gray background for visibility)
- CSS gradients: Use
linear-gradient() or radial-gradient() in CSS on block element backgrounds - automatically converted to PowerPoint
- Background images: Use
background-image: url(...) CSS property on block elements
- Block elements: Use
<div>, <section>, <header>, <footer>, <main>, <article>, <nav>, <aside> for containers with styling (all behave identically)
- Icons: Use inline SVG format or reference SVG files - SVG elements are automatically converted to images in PowerPoint
- Text balancing:
<h1> and <h2> elements are automatically balanced. Use data-balance attribute on other elements to auto-balance line lengths for better typography
- Layout: For slides with charts/tables/images, use either full-slide layout or two-column layout for better readability
Create and run a JavaScript file using the html2pptx library to convert HTML slides to PowerPoint and save the presentation
Run with: node your-script.js 2>&1
Use the html2pptx function to process each HTML file
Add charts and tables to placeholder areas using PptxGenJS API
Save the presentation using pptx.writeFile()
⚠️ CRITICAL: Your script MUST follow this example structure. Think aloud before writing the script to make sure that you correctly use the APIs. Do NOT call pptx.addSlide.
⚠️ CRITICAL: Use ES module import syntax (NOT CommonJS require). Create package.json with {"type": "module"} before running.
import pptxgen from "pptxgenjs";
import { html2pptx } from "@ant/html2pptx";
// Create a new pptx presentation
const pptx = new pptxgen();
pptx.layout = "LAYOUT_16x9"; // Must match HTML body dimensions
// Add an HTML-only slide
await html2pptx("slide1.html", pptx);
// Add a HTML slide with chart placeholders
const { slide: slide2, placeholders } = await html2pptx("slide2.html", pptx);
slide2.addChart(pptx.charts.LINE, chartData, placeholders[0]);
// Save the presentation
await pptx.writeFile("output.pptx");
Visual validation: Generate thumbnails and inspect for layout issues
- Create thumbnail grid:
python /mnt/skills/public/pptx/scripts/thumbnail.py output.pptx workspace/thumbnails --cols 4
- Read and carefully examine the thumbnail image for:
- Text cutoff: Text being cut off by header bars, shapes, or slide edges
- Text overlap: Text overlapping with other text or shapes
- Positioning issues: Content too close to slide boundaries or other elements
- Contrast issues: Insufficient contrast between text and backgrounds
- If issues found, adjust HTML margins/spacing/colors and regenerate the presentation
- Repeat until all slides are visually correct
Editing an existing PowerPoint presentation
To edit slides in an existing PowerPoint presentation, work with the raw Office Open XML (OOXML) format. This involves unpacking the .pptx file, editing the XML content, and repacking it.
Workflow
- MANDATORY - READ ENTIRE FILE: Read
ooxml.md (~500 lines) completely from start to finish. NEVER set any range limits when reading this file. Read the full file content for detailed guidance on OOXML structure and editing workflows before any presentation editing.
- Unpack the presentation:
python /mnt/skills/public/pptx/ooxml/scripts/unpack.py <office_file> <output_dir>
- Edit the XML files (primarily
ppt/slides/slide{N}.xml and related files)
- CRITICAL: Validate immediately after each edit and fix any validation errors before proceeding:
python /mnt/skills/public/pptx/ooxml/scripts/validate.py <dir> --original <file>
- Pack the final presentation:
python /mnt/skills/public/pptx/ooxml/scripts/pack.py <input_directory> <office_file>
Creating a new PowerPoint presentation using a template
To create a presentation that follows an existing template's design, duplicate and re-arrange template slides before replacing placeholder content.
Workflow
Extract template text AND create visual thumbnail grid:
- Extract text:
python -m markitdown template.pptx > template-content.md
- Read
template-content.md: Read the entire file to understand the contents of the template presentation. NEVER set any range limits when reading this file.
- Create thumbnail grids:
python /mnt/skills/public/pptx/scripts/thumbnail.py template.pptx
- See Creating Thumbnail Grids section for more details
Analyze template and save inventory to a file:
Visual Analysis: Review thumbnail grid(s) to understand slide layouts, design patterns, and visual structure
Create and save a template inventory file at template-inventory.md containing:
# Template Inventory Analysis
**Total Slides: [count]**
**IMPORTANT: Slides are 0-indexed (first slide = 0, last slide = count-1)**
## [Category Name]
- Slide 0: [Layout code if available] - Description/purpose
- Slide 1: [Layout code] - Description/purpose
- Slide 2: [Layout code] - Description/purpose
[... EVERY slide must be listed individually with its index ...]
Using the thumbnail grid: Reference the visual thumbnails to identify:
- Layout patterns (title slides, content layouts, section dividers)
- Image placeholder locations and counts
- Design consistency across slide groups
- Visual hierarchy and structure
This inventory file is REQUIRED for selecting appropriate templates in the next step
Create presentation outline based on template inventory:
- Review available templates from step 2.
- Choose an intro or title template for the first slide. This should be one of the first templates.
- Choose safe, text-based layouts for the other slides.
- CRITICAL: Match layout structure to actual content:
- Single-column layouts: Use for unified narrative or single topic
- Two-column layouts: Use ONLY when there are exactly 2 distinct items/concepts
- Three-column layouts: Use ONLY when there are exactly 3 distinct items/concepts
- Image + text layouts: Use ONLY when there are actual images to insert
- Quote layouts: Use ONLY for actual quotes from people (with attribution), never for emphasis
- Never use layouts with more placeholders than available content
- With 2 items, avoid forcing them into a 3-column layout
- With 4+ items, consider breaking into multiple slides or using a list format
- Count actual content pieces BEFORE selecting the layout
- Verify each placeholder in the chosen layout will be filled with meaningful content
- Select one option representing the best layout for each content section.
- Save
outline.md with content AND template mapping that leverages available designs
- Example template mapping:
# Template slides to use (0-based indexing)
# WARNING: Verify indices are within range! Template with 73 slides has indices 0-72
# Mapping: slide numbers from outline -> template slide indices
template_mapping = [
0, # Use slide 0 (Title/Cover)
34, # Use slide 34 (B1: Title and body)
34, # Use slide 34 again (duplicate for second B1)
50, # Use slide 50 (E1: Quote)
54, # Use slide 54 (F2: Closing + Text)
]
Duplicate, reorder, and delete slides using rearrange.py:
- Use the
scripts/rearrange.py script to create a new presentation with slides in the desired order:python /mnt/skills/public/pptx/scripts/rearrange.py template.pptx working.pptx 0,34,34,50,52
- The script handles duplicating repeated slides, deleting unused slides, and reordering automatically
- Slide indices are 0-based (first slide is 0, second is 1, etc.)
- The same slide index can appear multiple times to duplicate that slide
Extract ALL text using the inventory.py script:
Run inventory extraction:
python /mnt/skills/public/pptx/scripts/inventory.py working.pptx text-inventory.json
Read text-inventory.json: Read the entire text-inventory.json file to understand all shapes and their properties. NEVER set any range limits when reading this file.
The inventory JSON structure:
{
"slide-0": {
"shape-0": {
"placeholder_type": "TITLE", // or null for non-placeholders
"left": 1.5, // position in inches
"top": 2.0,
"width": 7.5,
"height": 1.2,
"paragraphs": [
{
"text": "Paragraph text",
// Optional properties (only included when non-default):
"bullet": true, // explicit bullet detected
"level": 0, // only included when bullet is true
"alignment": "CENTER", // CENTER, RIGHT (not LEFT)
"space_before": 10.0, // space before paragraph in points
"space_after": 6.0, // space after paragraph in points
"line_spacing": 22.4, // line spacing in points
"font_name": "Arial", // from first run
"font_size": 14.0, // in points
"bold": true,
"italic": false,
"underline": false,
"color": "FF0000" // RGB color
}
]
}
}
}
Key features:
- Slides: Named as "slide-0", "slide-1", etc.
- Shapes: Ordered by visual position (top-to-bottom, left-to-right) as "shape-0", "shape-1", etc.
- Placeholder types: TITLE, CENTER_TITLE, SUBTITLE, BODY, OBJECT, or null
- Default font size:
default_font_size in points extracted from layout placeholders (when available)
- Slide numbers are filtered: Shapes with SLIDE_NUMBER placeholder type are automatically excluded from inventory
- Bullets: When
bullet: true, level is always included (even if 0)
- Spacing:
space_before, space_after, and line_spacing in points (only included when set)
- Colors:
color for RGB (e.g., "FF0000"), theme_color for theme colors (e.g., "DARK_1")
- Properties: Only non-default values are included in the output
Generate replacement text and save the data to a JSON file
Based on the text inventory from the previous step:
- CRITICAL: First verify which shapes exist in the inventory - only reference shapes that are actually present
- VALIDATION: The replace.py script validates that all shapes in the replacement JSON exist in the inventory
- Referencing a non-existent shape produces an error showing available shapes
- Referencing a non-existent slide produces an error indicating the slide doesn't exist
- All validation errors are shown at once before the script exits
- IMPORTANT: The replace.py script uses inventory.py internally to identify ALL text shapes
- AUTOMATIC CLEARING: ALL text shapes from the inventory are cleared unless "paragraphs" are provided for them
- Add a "paragraphs" field to shapes that need content (not "replacement_paragraphs")
- Shapes without "paragraphs" in the replacement JSON have their text cleared automatically
- Paragraphs with bullets are automatically left aligned. Avoid setting the
alignment property when "bullet": true
- Generate appropriate replacement content for placeholder text
- Use shape size to determine appropriate content length
- CRITICAL: Include paragraph properties from the original inventory - don't just provide text
- IMPORTANT: When bullet: true, do NOT include bullet symbols (•, -, *) in text - they're added automatically
- ESSENTIAL FORMATTING RULES:
- Headers/titles should typically have
"bold": true
- List items should have
"bullet": true, "level": 0 (level is required when bullet is true)
- Preserve any alignment properties (e.g.,
"alignment": "CENTER" for centered text)
- Include font properties when different from default (e.g.,
"font_size": 14.0, "font_name": "Lora")
- Colors: Use
"color": "FF0000" for RGB or "theme_color": "DARK_1" for theme colors
- The replacement script expects properly formatted paragraphs, not just text strings
- Overlapping shapes: Prefer shapes with larger default_font_size or more appropriate placeholder_type
- Save the updated inventory with replacements to
replacement-text.json
- WARNING: Different template layouts have different shape counts - always check the actual inventory before creating replacements
Example paragraphs field showing proper formatting:
"paragraphs": [
{
"text": "New presentation title text",
"alignment": "CENTER",
"bold": true
},
{
"text": "Section Header",
"bold": true
},
{
"text": "First bullet point without bullet symbol",
"bullet": true,
"level": 0
},
{
"text": "Red colored text",
"color": "FF0000"
},
{
"text": "Theme colored text",
"theme_color": "DARK_1"
},
{
"text": "Regular paragraph text without special formatting"
}
]
Shapes not listed in the replacement JSON are automatically cleared:
{
"slide-0": {
"shape-0": {
"paragraphs": [...] // This shape gets new text
}
// shape-1 and shape-2 from inventory will be cleared automatically
}
}
Common formatting patterns for presentations:
- Title slides: Bold text, sometimes centered
- Section headers within slides: Bold text
- Bullet lists: Each item needs
"bullet": true, "level": 0
- Body text: Usually no special properties needed
- Quotes: May have special alignment or font properties
Apply replacements using the replace.py script
python /mnt/skills/public/pptx/scripts/replace.py working.pptx replacement-text.json output.pptx
The script will:
- First extract the inventory of ALL text shapes using functions from inventory.py
- Validate that all shapes in the replacement JSON exist in the inventory
- Clear text from ALL shapes identified in the inventory
- Apply new text only to shapes with "paragraphs" defined in the replacement JSON
- Preserve formatting by applying paragraph properties from the JSON
- Handle bullets, alignment, font properties, and colors automatically
- Save the updated presentation
Example validation errors:
ERROR: Invalid shapes in replacement JSON:
- Shape 'shape-99' not found on 'slide-0'. Available shapes: shape-0, shape-1, shape-4
- Slide 'slide-999' not found in inventory
ERROR: Replacement text made overflow worse in these shapes:
- slide-0/shape-2: overflow worsened by 1.25" (was 0.00", now 1.25")
Creating Thumbnail Grids
To create visual thumbnail grids of PowerPoint slides for quick analysis and reference:
python /mnt/skills/public/pptx/scripts/thumbnail.py template.pptx [output_prefix]
Features:
- Creates:
thumbnails.jpg (or thumbnails-1.jpg, thumbnails-2.jpg, etc. for large decks)
- Default: 5 columns, max 30 slides per grid (5×6)
- Custom prefix:
python /mnt/skills/public/pptx/scripts/thumbnail.py template.pptx my-grid
- Note: The output prefix should include the path if you want output in a specific directory (e.g.,
workspace/my-grid)
- Adjust columns:
--cols 4 (range: 3-6, affects slides per grid)
- Grid limits: 3 cols = 12 slides/grid, 4 cols = 20, 5 cols = 30, 6 cols = 42
- Slides are zero-indexed (Slide 0, Slide 1, etc.)
Use cases:
- Template analysis: Quickly understand slide layouts and design patterns
- Content review: Visual overview of entire presentation
- Navigation reference: Find specific slides by their visual appearance
- Quality check: Verify all slides are properly formatted
Examples:
# Basic usage
python /mnt/skills/public/pptx/scripts/thumbnail.py presentation.pptx
# Combine options: custom name, columns
python /mnt/skills/public/pptx/scripts/thumbnail.py template.pptx analysis --cols 4
Converting Slides to Images
To visually analyze PowerPoint slides, convert them to images using a two-step process:
Convert PPTX to PDF:
soffice --headless --convert-to pdf template.pptx
Convert PDF pages to JPEG images:
pdftoppm -jpeg -r 150 template.pdf slide
This creates files like slide-1.jpg, slide-2.jpg, etc.
Options:
-r 150: Sets resolution to 150 DPI (adjust for quality/size balance)
-jpeg: Output JPEG format (use -png for PNG if preferred)
-f N: First page to convert (e.g., -f 2 starts from page 2)
-l N: Last page to convert (e.g., -l 5 stops at page 5)
slide: Prefix for output files
Example for specific range:
pdftoppm -jpeg -r 150 -f 2 -l 5 template.pdf slide # Converts only pages 2-5
Design Guidelines (MANDATORY)
Every presentation must have intentional visual design. Never create unstyled slides.
- Analyze the topic first: What colors, mood, and tone fit the subject?
- Choose a color palette: Select 2-3 colors that match the content. Reference
css.md for available CSS variables.
- Use consistent typography: Headings in bold/larger size, body in regular weight. Stick to web-safe fonts.
- Apply visual hierarchy: Use size, weight, color, and spacing to guide the reader's eye.
- Keep slides concise: 3-5 bullet points max, 1-2 sentence paragraphs. This is a presentation, not a report.
Example CSS override for a tech presentation:
:root {
--color-primary: #2563eb;
--color-surface: #0f172a;
--color-surface-foreground: #f8fafc;
--font-family-display: 'Trebuchet MS', sans-serif;
}
For brand-specific presentations, ask the user for brand colors/fonts and apply them as CSS variable overrides.
Code Style Guidelines
IMPORTANT: When generating code for PPTX operations:
- Write concise code
- Avoid verbose variable names and redundant operations
- Avoid unnecessary print statements
Dependencies
Required dependencies (should already be installed):
- markitdown:
pip install "markitdown[pptx]" (for text extraction from presentations)
- pptxgenjs:
npm install -g pptxgenjs (for creating presentations via html2pptx)
- playwright:
npm install -g playwright (for HTML rendering in html2pptx)
- react-icons:
npm install -g react-icons react react-dom (for icons in SVG format)
- LibreOffice:
sudo apt-get install libreoffice (for PDF conversion)
- Poppler:
sudo apt-get install poppler-utils (for pdftoppm to convert PDF to images)
- defusedxml:
pip install defusedxml (for secure XML parsing)
1---2name: pptx3description: Presentation creation, editing, and analysis. When Assistant needs to work with presentations (.pptx files) for: (1) Creating new presentations, (2) Modifying or editing content, (3) Working with layouts, (4) Adding comments or speaker notes, or any other presentation tasks4license: Proprietary. LICENSE.txt has complete terms5---67# PPTX creation, editing, and analysis89## Overview1011Create, edit, or analyze the contents of .pptx files when requested. A .pptx file is essentially a ZIP archive containing XML files and other resources. Different tools and workflows are available for different tasks.1213## Reading and analyzing content1415### Text extraction1617To read just the text content of a presentation, convert the document to markdown:1819```bash20# Convert document to markdown21python -m markitdown path-to-file.pptx22```2324### Raw XML access2526Use raw XML access for: comments, speaker notes, slide layouts, animations, design elements, and complex formatting. To access these features, unpack a presentation and read its raw XML contents.2728#### Unpacking a file2930`python /mnt/skills/public/pptx/ooxml/scripts/unpack.py <office_file> <output_dir>`313233#### Key file structures3435- `ppt/presentation.xml` - Main presentation metadata and slide references36- `ppt/slides/slide{N}.xml` - Individual slide contents (slide1.xml, slide2.xml, etc.)37- `ppt/notesSlides/notesSlide{N}.xml` - Speaker notes for each slide38- `ppt/comments/modernComment_*.xml` - Comments for specific slides39- `ppt/slideLayouts/` - Layout templates for slides40- `ppt/slideMasters/` - Master slide templates41- `ppt/theme/` - Theme and styling information42- `ppt/media/` - Images and other media files4344#### Typography and color extraction4546**To emulate example designs**, analyze the presentation's typography and colors first using the methods below:47481. **Read theme file**: Check `ppt/theme/theme1.xml` for colors (`<a:clrScheme>`) and fonts (`<a:fontScheme>`)492. **Sample slide content**: Examine `ppt/slides/slide1.xml` for actual font usage (`<a:rPr>`) and colors503. **Search for patterns**: Use grep to find color (`<a:solidFill>`, `<a:srgbClr>`) and font references across all XML files5152## Creating a new PowerPoint presentation **without a template**5354When creating a new PowerPoint presentation from scratch, use the **html2pptx** workflow to convert HTML slides to PowerPoint with accurate positioning.5556> **IMPORTANT: html2pptx is a JavaScript LIBRARY, not a CLI tool.** You MUST create a `.js` script with `import { html2pptx }` and run it with `node script.js`. Do NOT run `html2pptx`, `npx html2pptx`, or create config.json files — html2pptx has no CLI interface.5758### Workflow59601. **MANDATORY - READ ENTIRE FILE NOW**: Read [`html2pptx.md`](html2pptx.md) completely from start to finish. **NEVER set any range limits when reading this file.** Read the full file content for detailed syntax, critical formatting rules, and best practices before proceeding with presentation creation.612. **PREREQUISITE - Install html2pptx library**:62 - Check and install if needed: `npm list -g @ant/html2pptx || npm install -g skills/pptx/html2pptx.tgz`63 - **Note**: If you see "Cannot find module '@ant/html2pptx'" error later, the package isn't installed643. **CRITICAL**: Plan the presentation65 - Plan the shared aspects of the presentation. Describe the tone of the presentation's content and the colors and typography that should be used in the presentation.66 - Write a DETAILED outline of the presentation67 - For each slide, describe the slide's layout and contents68 - For each slide, write presenter notes (1 to 3 sentences per slide)694. **CRITICAL**: Set CSS variables70 - In a shared `.css` file, override CSS variables to use on each slide for colors, typography, and spacing. DO NOT create classes in this file.715. Create an HTML file for each slide with proper dimensions (e.g., 960px × 540px for 16:9)72 - Recall the outline, layout/content description, and speaker notes you wrote for this slide in Step 3. Think out loud how to best apply them to this slide.73 - Embed the contents of the shared `.css` file in a `<style>` element74 - Use `<p>`, `<h1>`-`<h6>`, `<ul>`, `<ol>` for all text content75 - **IMPORTANT:** Use CSS variables for colors, typography, and spacing76 - **IMPORTANT:** Use `row` `col` and `fit` classes for layout INSTEAD OF flexbox77 - Use `class="placeholder"` for areas where charts/tables will be added (render with gray background for visibility)78 - **CSS gradients**: Use `linear-gradient()` or `radial-gradient()` in CSS on block element backgrounds - automatically converted to PowerPoint79 - **Background images**: Use `background-image: url(...)` CSS property on block elements80 - **Block elements**: Use `<div>`, `<section>`, `<header>`, `<footer>`, `<main>`, `<article>`, `<nav>`, `<aside>` for containers with styling (all behave identically)81 - **Icons**: Use inline SVG format or reference SVG files - SVG elements are automatically converted to images in PowerPoint82 - **Text balancing**: `<h1>` and `<h2>` elements are automatically balanced. Use `data-balance` attribute on other elements to auto-balance line lengths for better typography83 - **Layout**: For slides with charts/tables/images, use either full-slide layout or two-column layout for better readability846. Create and run a JavaScript file using the [`html2pptx`](./html2pptx) library to convert HTML slides to PowerPoint and save the presentation8586 - Run with: `node your-script.js 2>&1`87 - Use the `html2pptx` function to process each HTML file88 - Add charts and tables to placeholder areas using PptxGenJS API89 - Save the presentation using `pptx.writeFile()`9091 - **⚠️ CRITICAL:** Your script MUST follow this example structure. Think aloud before writing the script to make sure that you correctly use the APIs. Do NOT call `pptx.addSlide`.92 - **⚠️ CRITICAL:** Use ES module `import` syntax (NOT CommonJS `require`). Create `package.json` with `{"type": "module"}` before running.9394 ```javascript95 import pptxgen from "pptxgenjs";96 import { html2pptx } from "@ant/html2pptx";9798 // Create a new pptx presentation99 const pptx = new pptxgen();100 pptx.layout = "LAYOUT_16x9"; // Must match HTML body dimensions101102 // Add an HTML-only slide103 await html2pptx("slide1.html", pptx);104105 // Add a HTML slide with chart placeholders106 const { slide: slide2, placeholders } = await html2pptx("slide2.html", pptx);107 slide2.addChart(pptx.charts.LINE, chartData, placeholders[0]);108109 // Save the presentation110 await pptx.writeFile("output.pptx");111 ```1121137. **Visual validation**: Generate thumbnails and inspect for layout issues114 - Create thumbnail grid: `python /mnt/skills/public/pptx/scripts/thumbnail.py output.pptx workspace/thumbnails --cols 4`115 - Read and carefully examine the thumbnail image for:116 - **Text cutoff**: Text being cut off by header bars, shapes, or slide edges117 - **Text overlap**: Text overlapping with other text or shapes118 - **Positioning issues**: Content too close to slide boundaries or other elements119 - **Contrast issues**: Insufficient contrast between text and backgrounds120 - If issues found, adjust HTML margins/spacing/colors and regenerate the presentation121 - Repeat until all slides are visually correct122123## Editing an existing PowerPoint presentation124125To edit slides in an existing PowerPoint presentation, work with the raw Office Open XML (OOXML) format. This involves unpacking the .pptx file, editing the XML content, and repacking it.126127### Workflow1281291. **MANDATORY - READ ENTIRE FILE**: Read [`ooxml.md`](ooxml.md) (~500 lines) completely from start to finish. **NEVER set any range limits when reading this file.** Read the full file content for detailed guidance on OOXML structure and editing workflows before any presentation editing.1302. Unpack the presentation: `python /mnt/skills/public/pptx/ooxml/scripts/unpack.py <office_file> <output_dir>`1313. Edit the XML files (primarily `ppt/slides/slide{N}.xml` and related files)1324. **CRITICAL**: Validate immediately after each edit and fix any validation errors before proceeding: `python /mnt/skills/public/pptx/ooxml/scripts/validate.py <dir> --original <file>`1335. Pack the final presentation: `python /mnt/skills/public/pptx/ooxml/scripts/pack.py <input_directory> <office_file>`134135## Creating a new PowerPoint presentation **using a template**136137To create a presentation that follows an existing template's design, duplicate and re-arrange template slides before replacing placeholder content.138139### Workflow1401411. **Extract template text AND create visual thumbnail grid**:142143 - Extract text: `python -m markitdown template.pptx > template-content.md`144 - Read `template-content.md`: Read the entire file to understand the contents of the template presentation. **NEVER set any range limits when reading this file.**145 - Create thumbnail grids: `python /mnt/skills/public/pptx/scripts/thumbnail.py template.pptx`146 - See [Creating Thumbnail Grids](#creating-thumbnail-grids) section for more details1471482. **Analyze template and save inventory to a file**:149150 - **Visual Analysis**: Review thumbnail grid(s) to understand slide layouts, design patterns, and visual structure151 - Create and save a template inventory file at `template-inventory.md` containing:152153 ```markdown154 # Template Inventory Analysis155156 **Total Slides: [count]**157 **IMPORTANT: Slides are 0-indexed (first slide = 0, last slide = count-1)**158159 ## [Category Name]160161 - Slide 0: [Layout code if available] - Description/purpose162 - Slide 1: [Layout code] - Description/purpose163 - Slide 2: [Layout code] - Description/purpose164 [... EVERY slide must be listed individually with its index ...]165 ```166167 - **Using the thumbnail grid**: Reference the visual thumbnails to identify:168 - Layout patterns (title slides, content layouts, section dividers)169 - Image placeholder locations and counts170 - Design consistency across slide groups171 - Visual hierarchy and structure172 - This inventory file is REQUIRED for selecting appropriate templates in the next step1731743. **Create presentation outline based on template inventory**:175176 - Review available templates from step 2.177 - Choose an intro or title template for the first slide. This should be one of the first templates.178 - Choose safe, text-based layouts for the other slides.179 - **CRITICAL: Match layout structure to actual content**:180 - Single-column layouts: Use for unified narrative or single topic181 - Two-column layouts: Use ONLY when there are exactly 2 distinct items/concepts182 - Three-column layouts: Use ONLY when there are exactly 3 distinct items/concepts183 - Image + text layouts: Use ONLY when there are actual images to insert184 - Quote layouts: Use ONLY for actual quotes from people (with attribution), never for emphasis185 - Never use layouts with more placeholders than available content186 - With 2 items, avoid forcing them into a 3-column layout187 - With 4+ items, consider breaking into multiple slides or using a list format188 - Count actual content pieces BEFORE selecting the layout189 - Verify each placeholder in the chosen layout will be filled with meaningful content190 - Select one option representing the **best** layout for each content section.191 - Save `outline.md` with content AND template mapping that leverages available designs192 - Example template mapping:193 ```194 # Template slides to use (0-based indexing)195 # WARNING: Verify indices are within range! Template with 73 slides has indices 0-72196 # Mapping: slide numbers from outline -> template slide indices197 template_mapping = [198 0, # Use slide 0 (Title/Cover)199 34, # Use slide 34 (B1: Title and body)200 34, # Use slide 34 again (duplicate for second B1)201 50, # Use slide 50 (E1: Quote)202 54, # Use slide 54 (F2: Closing + Text)203 ]204 ```2052064. **Duplicate, reorder, and delete slides using `rearrange.py`**:207208 - Use the `scripts/rearrange.py` script to create a new presentation with slides in the desired order:209 ```bash210 python /mnt/skills/public/pptx/scripts/rearrange.py template.pptx working.pptx 0,34,34,50,52211 ```212 - The script handles duplicating repeated slides, deleting unused slides, and reordering automatically213 - Slide indices are 0-based (first slide is 0, second is 1, etc.)214 - The same slide index can appear multiple times to duplicate that slide2152165. **Extract ALL text using the `inventory.py` script**:217218 - **Run inventory extraction**:219 ```bash220 python /mnt/skills/public/pptx/scripts/inventory.py working.pptx text-inventory.json221 ```222 - **Read text-inventory.json**: Read the entire text-inventory.json file to understand all shapes and their properties. **NEVER set any range limits when reading this file.**223224 - The inventory JSON structure:225226 ```json227 {228 "slide-0": {229 "shape-0": {230 "placeholder_type": "TITLE", // or null for non-placeholders231 "left": 1.5, // position in inches232 "top": 2.0,233 "width": 7.5,234 "height": 1.2,235 "paragraphs": [236 {237 "text": "Paragraph text",238 // Optional properties (only included when non-default):239 "bullet": true, // explicit bullet detected240 "level": 0, // only included when bullet is true241 "alignment": "CENTER", // CENTER, RIGHT (not LEFT)242 "space_before": 10.0, // space before paragraph in points243 "space_after": 6.0, // space after paragraph in points244 "line_spacing": 22.4, // line spacing in points245 "font_name": "Arial", // from first run246 "font_size": 14.0, // in points247 "bold": true,248 "italic": false,249 "underline": false,250 "color": "FF0000" // RGB color251 }252 ]253 }254 }255 }256 ```257258 - Key features:259 - **Slides**: Named as "slide-0", "slide-1", etc.260 - **Shapes**: Ordered by visual position (top-to-bottom, left-to-right) as "shape-0", "shape-1", etc.261 - **Placeholder types**: TITLE, CENTER_TITLE, SUBTITLE, BODY, OBJECT, or null262 - **Default font size**: `default_font_size` in points extracted from layout placeholders (when available)263 - **Slide numbers are filtered**: Shapes with SLIDE_NUMBER placeholder type are automatically excluded from inventory264 - **Bullets**: When `bullet: true`, `level` is always included (even if 0)265 - **Spacing**: `space_before`, `space_after`, and `line_spacing` in points (only included when set)266 - **Colors**: `color` for RGB (e.g., "FF0000"), `theme_color` for theme colors (e.g., "DARK_1")267 - **Properties**: Only non-default values are included in the output2682696. **Generate replacement text and save the data to a JSON file**270 Based on the text inventory from the previous step:271272 - **CRITICAL**: First verify which shapes exist in the inventory - only reference shapes that are actually present273 - **VALIDATION**: The replace.py script validates that all shapes in the replacement JSON exist in the inventory274 - Referencing a non-existent shape produces an error showing available shapes275 - Referencing a non-existent slide produces an error indicating the slide doesn't exist276 - All validation errors are shown at once before the script exits277 - **IMPORTANT**: The replace.py script uses inventory.py internally to identify ALL text shapes278 - **AUTOMATIC CLEARING**: ALL text shapes from the inventory are cleared unless "paragraphs" are provided for them279 - Add a "paragraphs" field to shapes that need content (not "replacement_paragraphs")280 - Shapes without "paragraphs" in the replacement JSON have their text cleared automatically281 - Paragraphs with bullets are automatically left aligned. Avoid setting the `alignment` property when `"bullet": true`282 - Generate appropriate replacement content for placeholder text283 - Use shape size to determine appropriate content length284 - **CRITICAL**: Include paragraph properties from the original inventory - don't just provide text285 - **IMPORTANT**: When bullet: true, do NOT include bullet symbols (•, -, \*) in text - they're added automatically286 - **ESSENTIAL FORMATTING RULES**:287 - Headers/titles should typically have `"bold": true`288 - List items should have `"bullet": true, "level": 0` (level is required when bullet is true)289 - Preserve any alignment properties (e.g., `"alignment": "CENTER"` for centered text)290 - Include font properties when different from default (e.g., `"font_size": 14.0`, `"font_name": "Lora"`)291 - Colors: Use `"color": "FF0000"` for RGB or `"theme_color": "DARK_1"` for theme colors292 - The replacement script expects **properly formatted paragraphs**, not just text strings293 - **Overlapping shapes**: Prefer shapes with larger default_font_size or more appropriate placeholder_type294 - Save the updated inventory with replacements to `replacement-text.json`295 - **WARNING**: Different template layouts have different shape counts - always check the actual inventory before creating replacements296297 Example paragraphs field showing proper formatting:298299 ```json300 "paragraphs": [301 {302 "text": "New presentation title text",303 "alignment": "CENTER",304 "bold": true305 },306 {307 "text": "Section Header",308 "bold": true309 },310 {311 "text": "First bullet point without bullet symbol",312 "bullet": true,313 "level": 0314 },315 {316 "text": "Red colored text",317 "color": "FF0000"318 },319 {320 "text": "Theme colored text",321 "theme_color": "DARK_1"322 },323 {324 "text": "Regular paragraph text without special formatting"325 }326 ]327 ```328329 **Shapes not listed in the replacement JSON are automatically cleared**:330331 ```json332 {333 "slide-0": {334 "shape-0": {335 "paragraphs": [...] // This shape gets new text336 }337 // shape-1 and shape-2 from inventory will be cleared automatically338 }339 }340 ```341342 **Common formatting patterns for presentations**:343344 - Title slides: Bold text, sometimes centered345 - Section headers within slides: Bold text346 - Bullet lists: Each item needs `"bullet": true, "level": 0`347 - Body text: Usually no special properties needed348 - Quotes: May have special alignment or font properties3493507. **Apply replacements using the `replace.py` script**351352 ```bash353 python /mnt/skills/public/pptx/scripts/replace.py working.pptx replacement-text.json output.pptx354 ```355356 The script will:357358 - First extract the inventory of ALL text shapes using functions from inventory.py359 - Validate that all shapes in the replacement JSON exist in the inventory360 - Clear text from ALL shapes identified in the inventory361 - Apply new text only to shapes with "paragraphs" defined in the replacement JSON362 - Preserve formatting by applying paragraph properties from the JSON363 - Handle bullets, alignment, font properties, and colors automatically364 - Save the updated presentation365366 Example validation errors:367368 ```369 ERROR: Invalid shapes in replacement JSON:370 - Shape 'shape-99' not found on 'slide-0'. Available shapes: shape-0, shape-1, shape-4371 - Slide 'slide-999' not found in inventory372 ```373374 ```375 ERROR: Replacement text made overflow worse in these shapes:376 - slide-0/shape-2: overflow worsened by 1.25" (was 0.00", now 1.25")377 ```378379## Creating Thumbnail Grids380381To create visual thumbnail grids of PowerPoint slides for quick analysis and reference:382383```bash384python /mnt/skills/public/pptx/scripts/thumbnail.py template.pptx [output_prefix]385```386387**Features**:388389- Creates: `thumbnails.jpg` (or `thumbnails-1.jpg`, `thumbnails-2.jpg`, etc. for large decks)390- Default: 5 columns, max 30 slides per grid (5×6)391- Custom prefix: `python /mnt/skills/public/pptx/scripts/thumbnail.py template.pptx my-grid`392 - Note: The output prefix should include the path if you want output in a specific directory (e.g., `workspace/my-grid`)393- Adjust columns: `--cols 4` (range: 3-6, affects slides per grid)394- Grid limits: 3 cols = 12 slides/grid, 4 cols = 20, 5 cols = 30, 6 cols = 42395- Slides are zero-indexed (Slide 0, Slide 1, etc.)396397**Use cases**:398399- Template analysis: Quickly understand slide layouts and design patterns400- Content review: Visual overview of entire presentation401- Navigation reference: Find specific slides by their visual appearance402- Quality check: Verify all slides are properly formatted403404**Examples**:405406```bash407# Basic usage408python /mnt/skills/public/pptx/scripts/thumbnail.py presentation.pptx409410# Combine options: custom name, columns411python /mnt/skills/public/pptx/scripts/thumbnail.py template.pptx analysis --cols 4412```413414## Converting Slides to Images415416To visually analyze PowerPoint slides, convert them to images using a two-step process:4174181. **Convert PPTX to PDF**:419420 ```bash421 soffice --headless --convert-to pdf template.pptx422 ```4234242. **Convert PDF pages to JPEG images**:425 ```bash426 pdftoppm -jpeg -r 150 template.pdf slide427 ```428 This creates files like `slide-1.jpg`, `slide-2.jpg`, etc.429430Options:431432- `-r 150`: Sets resolution to 150 DPI (adjust for quality/size balance)433- `-jpeg`: Output JPEG format (use `-png` for PNG if preferred)434- `-f N`: First page to convert (e.g., `-f 2` starts from page 2)435- `-l N`: Last page to convert (e.g., `-l 5` stops at page 5)436- `slide`: Prefix for output files437438Example for specific range:439440```bash441pdftoppm -jpeg -r 150 -f 2 -l 5 template.pdf slide # Converts only pages 2-5442```443444## Design Guidelines (MANDATORY)445446**Every presentation must have intentional visual design. Never create unstyled slides.**4474481. **Analyze the topic first**: What colors, mood, and tone fit the subject?4492. **Choose a color palette**: Select 2-3 colors that match the content. Reference `css.md` for available CSS variables.4503. **Use consistent typography**: Headings in bold/larger size, body in regular weight. Stick to web-safe fonts.4514. **Apply visual hierarchy**: Use size, weight, color, and spacing to guide the reader's eye.4525. **Keep slides concise**: 3-5 bullet points max, 1-2 sentence paragraphs. This is a presentation, not a report.453454Example CSS override for a tech presentation:455```css456:root {457 --color-primary: #2563eb;458 --color-surface: #0f172a;459 --color-surface-foreground: #f8fafc;460 --font-family-display: 'Trebuchet MS', sans-serif;461}462```463464For brand-specific presentations, ask the user for brand colors/fonts and apply them as CSS variable overrides.465466## Code Style Guidelines467468**IMPORTANT**: When generating code for PPTX operations:469470- Write concise code471- Avoid verbose variable names and redundant operations472- Avoid unnecessary print statements473474## Dependencies475476Required dependencies (should already be installed):477478- **markitdown**: `pip install "markitdown[pptx]"` (for text extraction from presentations)479- **pptxgenjs**: `npm install -g pptxgenjs` (for creating presentations via html2pptx)480- **playwright**: `npm install -g playwright` (for HTML rendering in html2pptx)481- **react-icons**: `npm install -g react-icons react react-dom` (for icons in SVG format)482- **LibreOffice**: `sudo apt-get install libreoffice` (for PDF conversion)483- **Poppler**: `sudo apt-get install poppler-utils` (for pdftoppm to convert PDF to images)484- **defusedxml**: `pip install defusedxml` (for secure XML parsing)