PPTX
@office-open/pptx
Generate, parse, and patch .pptx presentations with a declarative TypeScript API
Installation
pnpm add @office-open/pptx
npm install @office-open/pptx
yarn add @office-open/pptx
bun add @office-open/pptx
Quick Start
{
"slides": [
{
"children": [
{
"shape": {
"x": "1.3cm",
"y": "1.3cm",
"width": "20cm",
"height": "3cm",
"textBody": { "children": ["Hello World"] }
}
}
]
}
]
}
import { generatePresentation } from "@office-open/pptx";
const buffer = await generatePresentation({
slides: [
{
children: [
{
shape: {
x: "1.3cm",
y: "1.3cm",
width: "20cm",
height: "3cm",
textBody: { children: ["Hello World"] },
},
},
],
},
],
});
Main Components
| Component | Description |
|---|---|
slides array | Root presentation — array of slides with properties |
slide | A single slide with shapes, media, and layout |
shape | Rectangle, rounded rectangle, and custom geometry shapes |
group | Grouped shapes with collective transform |
| Text paragraphs and runs | Text paragraphs and runs inside shapes |
table with rows and cells | Tables with merged cells and styling |
image / picture | Embedded images on slides |
chart | Bar, line, pie, area, and scatter charts |
smartart | Predefined SmartArt diagrams |
video / audio | Embedded video and audio |
line / connector | Lines and connectors between elements |
transition | Slide transition effects |
animation | Shape entrance, emphasis, and exit animations |
background | Slide background — solid, gradient, and picture fills |
headers / footers | Slide footers with date, number, and text |
hyperlink | Clickable hyperlinks on shapes and text |
| Slide masters and layouts | Slide masters and layouts for consistent design |
notes | Speaker notes for each slide |
theme | Color schemes and font schemes |
modifyVerifier | Password protection for presentation modification |
photoAlbum | Photo album layout and frame settings |
ole | Embedded OLE objects |
lockedCanvas | Locked canvas for non-editable drawing objects |
Export Formats
Every async method has a synchronous counterpart (e.g., generatePresentationSync). See the page for the full list.
| Method | Returns | Use Case |
|---|---|---|
generatePresentation(opts) | Buffer | Node.js file I/O |
generatePresentation(opts, { type: "blob" }) | Blob | Browser downloads |
generatePresentation(opts, { type: "base64" }) | string | Data URLs, API payloads |
generatePresentation(opts, { type: "string" }) | string | Debugging, inspection |
generatePresentationStream(opts) | ReadableStream<Uint8Array> | Streaming large files |
Patching
Modify existing .pptx templates by replacing {{placeholder}} tokens with new content:
import { patchPresentation } from "@office-open/pptx";
const result = await patchPresentation({
outputType: "nodebuffer",
data: templateBuffer,
placeholders: {
title: [{ text: "Updated", bold: true }],
},
});
See for full documentation.
Parsing
Parse existing .pptx files into PresentationOptions for inspection or round-trip workflows:
import { parsePresentation } from "@office-open/pptx";
const opts = parsePresentation(buffer);
// opts.slides![0].children — shapes, tables, charts, etc.
// opts.slides![0].background — slide background
// opts.slides![0].transition — slide transition
// opts.slides![0].notes — speaker notes
// opts.title, opts.creator — core properties
// opts.size — slide size ("16:9", "4:3", or custom)
See for full documentation.
Slide Size
Use the size option to set slide dimensions. Accepts "16:9", "4:3", or a custom { width, height } object (in EMU or UniversalMeasure).
const buffer = await generatePresentation({
size: "16:9",
slides: [
// ...
],
});
| Size | Dimensions |
|---|---|
"16:9" | 13.33" × 7.5" (widescreen) |
"4:3" | 10" × 7.5" (standard) |
{ width, height } | Custom size in EMU or UniversalMeasure |