PPTX
Parsing
Parse existing .pptx files with parsePresentation and parsePptx
Parse existing .pptx files into structured data for inspection, modification, or round-trip workflows.
parsePresentation
The high-level API that parses a .pptx file into PresentationOptions that can be passed to generatePresentation(). Both parsePresentation and parsePptx accept any DataType input.
import { parsePresentation, generatePresentation } from "@office-open/pptx";
import { readFileSync, writeFileSync } from "node:fs";
const opts = parsePresentation(readFileSync("input.pptx"));
// Re-create and export
const buffer = await generatePresentation(opts);
writeFileSync("output.pptx", buffer);
Parsed Presentation Structure
parsePresentation returns a PresentationOptions object:
| Property | Type | Description |
|---|---|---|
slides | SlideOptions[] | Array of slide options |
masters | MasterDefinition[] | Master definitions (only when multiple masters) |
title | string | Document title (from core properties) |
creator | string | Document creator (from core properties) |
size | SlideSize | Slide size ("16:9", "4:3", or custom) |
show | ShowOptions | Slide show settings |
Parsed Slide Structure
Each parsed slide is a SlideOptions object:
| Property | Type | Description |
|---|---|---|
children | SlideChild[] | Shapes, tables, charts, connectors |
background | BackgroundOptions | Slide background (solid/gradient) |
transition | TransitionOptions | Slide transition effect |
notes | string | Speaker notes text |
layout | SlideLayoutType | Layout type (e.g., "blank", "title") |
master | string | Master name (for multi-master files) |
comments | SlideCommentOptions[] | Slide comments (author, text, position) |
Parsed Slide Children
Each child uses a discriminated union with a single key identifying the type:
// Shape
{ shape: { x, y, width, height, textBody, fill, outline, effects, geometry, ... } }
// Table
{ table: { x, y, width, height, rows, columnWidths, firstRow, bandRow, ... } }
// Chart
{ chart: { x, y, width, height, type, title, categories, series, showLegend } }
// SmartArt
{ smartart: { x, y, width, height, nodes, layout, style, color } }
// Connector
{ connector: { x1, y1, x2, y2, beginArrowhead, endArrowhead, outline } }
// Group
{ group: { x, y, width, height, rotation, children } }
// Picture
{ picture: { x, y, width, height, data } }
// Line
{ line: { x1, y1, x2, y2, outline, ... } }
// Video
{ video: { x, y, width, height, data, type, poster?, ... } }
// Audio
{ audio: { x, y, width, height, data, type, ... } }
Round-trip Example
Parse a file, modify it, and export:
import { parsePresentation, generatePresentation } from "@office-open/pptx";
import { readFileSync, writeFileSync } from "node:fs";
const parsed = parsePresentation(readFileSync("template.pptx"));
// Add a new slide to the end
parsed.slides!.push({
children: [
{
shape: {
x: "2.6cm",
y: "2.6cm",
width: "15.9cm",
height: "10.6cm",
fill: "4472C4",
textBody: { text: "New Slide" },
},
},
],
});
const buffer = await generatePresentation(parsed);
writeFileSync("modified.pptx", buffer);
Or use the JSON API directly:
{
"children": [
{
"shape": {
"x": "2.6cm",
"y": "2.6cm",
"width": "15.9cm",
"height": "10.6cm",
"fill": "4472C4",
"textBody": { "text": "New Slide" }
}
}
]
}
{
children: [
{
shape: {
x: "2.6cm",
y: "2.6cm",
width: "15.9cm",
height: "10.6cm",
fill: "4472C4",
textBody: { text: "New Slide" },
},
},
],
}
parsePptx
The low-level API that returns raw document structure for advanced use cases:
import { parsePptx } from "@office-open/pptx";
const pptx = parsePptx(buffer);
PptxDocument API
| Property | Type | Description |
|---|---|---|
doc | ParsedArchive | Underlying archive for part access |
presentation | Element | p:presentation root element |
slides | string[] | Slide paths (ppt/slides/slide1.xml) |
slideMasters | string[] | Slide master paths |
slideLayouts | string[] | Slide layout paths |
notesSlides | string[] | Notes slide paths |
partRefs | PptxPartRefs | References to media, charts, themes |
presProps | string | Presentation properties path |
viewProps | string | View properties path |
coreProps | string | Core (Dublin Core) metadata path |
appProps | string | Application properties path |
Accessing Parts
const pptx = parsePptx(buffer);
// Read a slide's raw XML
const slideEl = pptx.doc.get(pptx.slides[0]);
// List all media files
console.log(pptx.partRefs.media);
// Access chart data
for (const chartPath of pptx.partRefs.charts) {
const chartEl = pptx.doc.get(chartPath);
}
Supported Parsing Features
| Feature | Details |
|---|---|
| Shapes | Position, geometry, fill (solid/gradient/pattern/blip), outline, effects |
| Tables | Rows, cells, columnWidths, table style flags, borders |
| Charts | Type, title, categories, series, legend visibility |
| SmartArt | Node tree structure, layout, style, color |
| Connectors | Position, arrowheads, outline |
| Groups | Position, rotation, nested children |
| Pictures | Position, embedded image data |
| Lines | Position (x1/y1/x2/y2), outline with dash style |
| Video | Position, embedded video data, poster frame |
| Audio | Position, embedded audio data |
| Transitions | Type, speed, direction |
| Backgrounds | Solid and gradient fills |
| Notes | Speaker notes text |
| Animations | Entrance/exit/emphasis types, trigger, delay, duration |
| Comments | Author, text, position, date |
| Effects | outerShadow, innerShadow, glow, reflection, softEdge |
| Rich Text | Bold, italic, underline, strike, font, size, color, spacing |
Browser Usage
const fileInput = document.querySelector("input[type=file]");
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();
const opts = parsePresentation(arrayBuffer);
console.log("Slides:", opts.slides?.length);
Tips
parsePresentationreturns plain objects compatible with the JSON API — use{ shape: {...} }style, notnew Shape().- Parsed data can be passed directly to
generatePresentation(parsed)for a complete round-trip. mastersis only populated when the file contains multiple slide masters — single-master files returnmasters: undefined.- Use
parsePptxwhen you need low-level access to XML parts or relationship data. - Not all PPTX features are preserved during parsing — test with your specific files.