PPTX
@office-open/pptx
Generate .pptx presentations with a declarative TypeScript API
Installation
pnpm add @office-open/pptx
Quick Start
import {
Presentation,
Packer,
Slide,
Shape,
TextBody,
Paragraph,
TextRun,
} from "@office-open/pptx";
const presentation = new Presentation({
slides: [
new Slide({
children: [
new Shape({
body: new TextBody({
children: [
new Paragraph({
children: [new TextRun("Hello World")],
}),
],
}),
}),
],
}),
],
});
const buffer = await Packer.toBuffer(presentation);
Main Components
| Component | Description |
|---|---|
Presentation | Root presentation container with slides and properties |
Slide | A single slide with shapes, media, and layout |
Shape | Rectangle, rounded rectangle, and custom geometry shapes |
GroupShape | Grouped shapes with collective transform |
TextBody, Paragraph, TextRun | Rich text content inside shapes |
Table, TableRow, TableCell | Tables with merged cells and styling |
Picture | Embedded images on slides |
ChartFrame | Bar, line, pie, area, and scatter charts |
SmartArtFrame | Predefined SmartArt diagrams |
VideoFrame, AudioFrame | Embedded video and audio |
LineShape, ConnectorShape | Lines and connectors between elements |
Transition | Slide transition effects |
Animation | Shape entrance, emphasis, and exit animations |
HeaderFooter | Slide footers with date, number, and text |
Export Formats
| Method | Returns | Use Case |
|---|---|---|
Packer.toBuffer(doc) | Uint8Array | Node.js file I/O |
Packer.toBlob(doc) | Blob | Browser downloads |
Packer.toBase64String(doc) | string | Data URLs, API payloads |
Packer.toString(doc) | string | Debugging, inspection |
Packer.toStream(doc) | ReadableStream | Streaming large files |
Slide Size Presets
import { SlideSizePreset } from "@office-open/pptx";
const presentation = new Presentation({
slideSize: SlideSizePreset.WIDESCREEN_16X9,
slides: [
// ...
],
});
Available presets:
| Preset | Dimensions |
|---|---|
WIDE | 13.33" × 7.5" (widescreen) |
STANDARD_4X3 | 10" × 7.5" (standard) |
WIDESCREEN_16X10 | 10" × 6.25" |
WIDESCREEN_16X9 | 13.33" × 7.5" |