Batch PPT Conversion: A Safe CLI and Automation Workflow
Design a repeatable PPT batch process with canaries, logs, validation and rollback.
Canary Conversion: Early Warning for Systemic Failure
Before touching the full corpus, select five files that represent the diversity of the source set:
- One with embedded images (JPEG, PNG, EMF)
- One with speaker notes
- One with multiple master slides
- One with SmartArt or charts
- One with a known-clean simple layout
Convert these five files with the same engine and flags intended for the batch. Check:
- Exit code — Must be 0.
- Slide count — Must match the source exactly.
- File size — Should fall within 20% of expected range. Binary PPT often shrinks during conversion; PPTX with embedded fonts may grow.
- MIME type — Must be
application/vnd.openxmlformats-officedocument.presentationml.presentationfor PPTX output.
If any canary fails, stop the pipeline. Investigate the engine version, missing dependencies (e.g., libreoffice-java-common), or a corrupted source before proceeding. A canary failure indicates systemic breakage that will affect every file in the batch.
Parallel Batch Execution with Failure Logging
Use a job-based runner: GNU parallel, Python concurrent.futures, or a Makefile with -j. For each file:
libreoffice --headless --convert-to pptx --outdir /tmp/staging "$source"
Capture three data points per file:
- Exit code
- Stderr — LibreOffice prints font warnings to stderr. Log these; do not discard them.
- Elapsed wall time — Files that hang beyond 5 minutes must be killed and logged.
Write every conversion result to a structured JSON Lines log:
{"source":"presentation.ppt","target":"presentation.pptx","exit":0,"stderr":"","elapsed_s":1.2,"slide_count_from":12,"slide_count_to":12}
Keep all outputs in a staging directory. Do not move any file to the final location until validation completes.
Validation: Checksum, Slide Count, and MIME Verification
After the batch finishes, run a validation pass over every file in staging. Four checks are mandatory:
- MIME type — Use
file --mime-typeor Python'smimetypes. Reject any output that is not a PPTX. - Slide count — Read the XML from
ppt/slides/inside the ZIP. Compare to the original PPT's slide count parsed viapython-pptxorolefile. A mismatch indicates conversion loss. - Checksum uniqueness — If two outputs share an identical SHA-256 hash but different source filenames, the converter may have returned a template default. Flag for manual review.
- ZIP integrity — Run
zip -Ton every PPTX. Corrupted inner XML will cause LibreOffice to crash when opening the file.
Only files that pass all four checks move to the final directory. Failures remain in staging for investigation.
Rollback Strategy: Atomic Replacement and Staging Directories
The final output directory must never contain partial results. Implement a two-stage move:
- Write all validated outputs to
/output/staging/. - After validation, rename
/output/staging/to/output/final/using an atomic filesystem rename on the same filesystem. No copy occurs. - Preserve the previous
/output/final/under a timestamped backup directory for 48 hours.
This enables immediate rollback by swapping directories. Do not delete original PPT files until the batch is confirmed clean across all environments.
Edge Cases: Encrypted Files, Macros, and Corrupt Originals
- Encrypted PPT — LibreOffice prompts for a password on stdin. In batch mode, this causes an indefinite hang. Pre-scan with
fileorolecatfor theEncryptedPackageflag. Skip encrypted files or decrypt them in a separate manual step. - Macro-enabled PPT (PPS, PPTM) — Converting to PPTX strips macros by default. Log a warning. If macros are detected in the source, preserve the
.pptmextension on the output. - Corrupt originals — If
olefileorpython-pptxraises anOLEErroron open, log the file as unrecoverable and skip it. Do not attempt repair. The PPT binary specification (reference) defines no recovery mechanism for broken offset tables.
Log Schema and Alert Thresholds
Every batch run writes a single JSON Lines file with the following fields per file:
| Field | Type | Example |
|---|---|---|
| source_name | string | "Q3_report.ppt" |
| sourcesizebytes | int | 2048000 |
| target_name | string | "Q3_report.pptx" |
| exit_code | int | 0 |
| stderr | string | "font 'Calibri' not found" |
| elapsed_s | float | 2.3 |
| slidecountmatch | bool | true |
| mime_valid | bool | true |
| checksum_unique | bool | true |
| final_action | string | "moved" / "failed" / "skipped" |
Alert thresholds:
- More than 2% of files with exit code != 0
- More than 1% of files with slide count mismatch
- Any single file exceeding 300 seconds conversion time
These thresholds are conservative starting points. Tune them after observing your first 1,000 conversions against your specific corpus.
Hard Limits
- Maximum file size: 500 MB per source PPT. Larger files risk OOM kills in headless LibreOffice.
- Maximum batch size: 10,000 files per run. Beyond this, JSON Lines log files become unwieldy and validation pass duration exceeds practical limits.
- Maximum parallel workers: CPU cores minus one, capped at 8. LibreOffice headless instances are memory-heavy; oversubscription triggers swapping.
- Staging directory: Must reside on the same filesystem as the final output directory to guarantee atomic rename.