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:

PropertyTypeDescription
slidesSlideOptions[]Array of slide options
mastersMasterDefinition[]Master definitions (only when multiple masters)
titlestringDocument title (from core properties)
creatorstringDocument creator (from core properties)
sizeSlideSizeSlide size ("16:9", "4:3", or custom)
showShowOptionsSlide show settings

Parsed Slide Structure

Each parsed slide is a SlideOptions object:

PropertyTypeDescription
childrenSlideChild[]Shapes, tables, charts, connectors
backgroundBackgroundOptionsSlide background (solid/gradient)
transitionTransitionOptionsSlide transition effect
notesstringSpeaker notes text
layoutSlideLayoutTypeLayout type (e.g., "blank", "title")
masterstringMaster name (for multi-master files)
commentsSlideCommentOptions[]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" }
      }
    }
  ]
}

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

PropertyTypeDescription
docParsedArchiveUnderlying archive for part access
presentationElementp:presentation root element
slidesstring[]Slide paths (ppt/slides/slide1.xml)
slideMastersstring[]Slide master paths
slideLayoutsstring[]Slide layout paths
notesSlidesstring[]Notes slide paths
partRefsPptxPartRefsReferences to media, charts, themes
presPropsstringPresentation properties path
viewPropsstringView properties path
corePropsstringCore (Dublin Core) metadata path
appPropsstringApplication 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

FeatureDetails
ShapesPosition, geometry, fill (solid/gradient/pattern/blip), outline, effects
TablesRows, cells, columnWidths, table style flags, borders
ChartsType, title, categories, series, legend visibility
SmartArtNode tree structure, layout, style, color
ConnectorsPosition, arrowheads, outline
GroupsPosition, rotation, nested children
PicturesPosition, embedded image data
LinesPosition (x1/y1/x2/y2), outline with dash style
VideoPosition, embedded video data, poster frame
AudioPosition, embedded audio data
TransitionsType, speed, direction
BackgroundsSolid and gradient fills
NotesSpeaker notes text
AnimationsEntrance/exit/emphasis types, trigger, delay, duration
CommentsAuthor, text, position, date
EffectsouterShadow, innerShadow, glow, reflection, softEdge
Rich TextBold, 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

  • parsePresentation returns plain objects compatible with the JSON API — use { shape: {...} } style, not new Shape().
  • Parsed data can be passed directly to generatePresentation(parsed) for a complete round-trip.
  • masters is only populated when the file contains multiple slide masters — single-master files return masters: undefined.
  • Use parsePptx when you need low-level access to XML parts or relationship data.
  • Not all PPTX features are preserved during parsing — test with your specific files.
Copyright © 2026