PPT Slide Merge Tool
Overview
Merge every N slides from a PowerPoint file into a single high-resolution image, automatically extracting student names from slide content as filenames. Designed for end-of-course PPT batch export, student report merging, and similar scenarios.
Cross-platform: Windows (WPS/PowerPoint COM), macOS & Linux (LibreOffice).
When to Use
This skill triggers when users request:
- Merge every N slides from a PPT into one image
- Export PPT content grouped by student name
- Batch convert end-of-course PPTs to images
- Combine slides and name files by student
Workflow
Step 1: Environment Check
Detect the operating system and choose the appropriate export method:
- Windows: Try WPS/PowerPoint COM first, fallback to LibreOffice
- macOS / Linux: Use LibreOffice (free, one-time install)
Ensure Python dependencies are installed. Install missing ones:
# All platforms
pip install python-pptx Pillow PyMuPDF
# Windows only (for COM support)
pip install pywin32
Step 2: (macOS only) Ensure LibreOffice
On macOS, LibreOffice is required. Install once:
- brew install --cask libreoffice (Homebrew)
- Or download from https://www.libreoffice.org/
The script automatically detects LibreOffice at common paths.
Step 3: Extract Student Names
Use scripts/merge_slides.py function extract_student_names():
- Every N slides form one group (default N=3)
- Two strategies: "XX同学" pattern (e.g. "子琛同学知识积累程度总览") or standalone 2-5 char Chinese name
- If no name found, use "unknown_student_N"
Step 4: Export Slides as Images
Cross-platform slide export:
Windows (COM):
- Resolution: 1920x1080
- Add 0.3s delay between exports to avoid COM errors
- Auto-retry up to 3 times on failure
- Do NOT set app.Visible = 1 - causes COM error
macOS / Linux (LibreOffice):
- PPTX → PDF via LibreOffice headless
- PDF pages → PNG via PyMuPDF (fitz)
- Same output resolution: 1920x1080
Step 5: Merge Images
Use Pillow to vertically merge every N slide images:
- 20px white padding between images
- Output size: width=slide width, height=Nslide height+(N-1)padding
- Last group with fewer than N slides also merges into one
Step 6: Save Output
- Filename = student name (special chars replaced with underscore)
- Default format: PNG (configurable to JPG)
- Save to
merged_slides/<ppt_name>图片/subfolder - Auto-clean temporary single-slide images
Script Usage
Main script: scripts/merge_slides.py
Single PPT
python scripts/merge_slides.py "path/to/file.pptx"
Batch Folder
python scripts/merge_slides.py "path/to/folder"
Scans all .pptx and .ppt files in the folder and processes them sequentially.
Configurable Parameters
Edit the config section at the top of scripts/merge_slides.py:
| Parameter | Default | Description |
|---|---|---|
| SLIDES_PER_GROUP | 3 | Slides per merged group |
| EXPORT_WIDTH | 1920 | Export width in pixels |
| EXPORT_HEIGHT | 1080 | Export height in pixels |
| PADDING | 20 | Gap between merged images in pixels |
| OUTPUT_FORMAT | PNG | Output format: PNG or JPG |