PPTX

Parsing

Read and modify existing .pptx files with parsePptx and PptxDocument

Read existing .pptx files and inspect or modify their contents using parsePptx.

Parse a File

import { parsePptx } from "@office-open/pptx";
import fs from "node:fs";

const buffer = fs.readFileSync("existing.pptx");
const doc = await parsePptx(buffer);

PptxDocument API

The returned PptxDocument provides access to the presentation data:

const doc = await parsePptx(buffer);

// Presentation metadata
doc.title; // string
doc.creator; // string

// Slide count
doc.slides.length;

// Access individual slides
const firstSlide = doc.slides[0];

Inspect Slides

for (const slide of doc.slides) {
    // Access slide properties
    console.log("Slide children:", slide.children);
    console.log("Slide notes:", slide.notes);
    console.log("Slide background:", slide.background);
}

Modify and Re-export

Parse a file, modify it, and export:

import {
    parsePptx,
    Presentation,
    Slide,
    Shape,
    Paragraph,
    TextRun,
    Packer,
} from "@office-open/pptx";
import fs from "node:fs";

// Parse existing file
const buffer = fs.readFileSync("template.pptx");
const doc = await parsePptx(buffer);

// Create a new presentation using parsed data
const pres = new Presentation({
    title: doc.title,
    creator: doc.creator,
    slides: [
        // Keep original slides
        ...doc.slides,

        // Add a new slide
        new Slide({
            children: [
                new Shape({
                    x: 1,
                    y: 1,
                    width: 8,
                    height: 5,
                    paragraphs: [
                        new Paragraph({
                            alignment: "center",
                            children: [
                                new TextRun({ text: "New Slide Added", fontSize: 36, bold: true }),
                            ],
                        }),
                    ],
                }),
            ],
        }),
    ],
});

// Export the modified presentation
const newBuffer = await Packer.toBuffer(pres);
fs.writeFileSync("modified.pptx", newBuffer);

Parse from Blob (Browser)

const fileInput = document.querySelector("input[type=file]");
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();

const doc = await parsePptx(new Uint8Array(arrayBuffer));
console.log("Slides:", doc.slides.length);

Tips

  • parsePptx accepts Buffer, Uint8Array, or ArrayBuffer.
  • Parsed slides can be reused in new Presentation instances.
  • Not all PPTX features may be fully preserved during parsing — test with your specific files.
  • For large files, consider streaming the input rather than loading the entire buffer into memory.
Copyright © 2026