pptx

 
 

Open Source JavaScript Library for PowerPoint

Create, Edit, Validate & Animate PPTX Files in Node.js & Browser with Full ECMA-376 Compliance.

What is pptx?

@office-kit/pptx is a modern, typed JavaScript library for generating and editing PowerPoint (.pptx) files in both Node.js and browser environments. Built around the ECMA-376 PresentationML specification, it provides a robust object model that mirrors the official XML schema. Unlike many alternatives, it delivers a single ESM bundle that works consistently across environments, avoids fragile string-based XML, and outputs files validated against Microsoft’s Open XML SDK validator.

The library supports two workflows: editing existing templates and authoring decks from scratch. It handles slides, shapes, text, tables, charts, animations, comments, and transitions with strong typing and tree-shaking support for minimal bundle size (~60 KB for basic load/save). Its design ensures round-trip safety—unmodeled content is preserved, not stripped—making it ideal for production use where schema validity and cross-platform compatibility (PowerPoint, Keynote, Google Slides, LibreOffice) are critical.

Previous Next

Getting Started with pptx

Install @office-kit/pptx via npm, pnpm, or yarn. The library is distributed as an ESM bundle and supports tree-shaking for minimal footprint. After installation, import functions like `loadPresentation`, `savePresentation`, or `createPresentation` to begin authoring or editing PPTX files. The API is consistent across Node.js and browser environments, and the official [pptx GitHub](https://github.com/office-kit/pptx) repository includes detailed usage examples, validation tools, and a skill guide for AI-assisted development.

Install pptx via NPM, pnpm, or Yarn

# npm
npm install @office-kit/pptx

# pnpm
pnpm add @office-kit/pptx

# yarn
yarn add @office-kit/pptx

Edit PowerPoint Templates

Template editing is a core strength of @office-kit/pptx. You can load an existing PPTX file, locate placeholders (e.g., title, body), and replace text programmatically—ideal for dynamic report generation. The library supports token-based replacement across all slides, making batch updates effortless. It preserves layout integrity and ensures output remains compatible with PowerPoint, Keynote, and Google Slides. This workflow is especially useful for templated presentations where only content changes between runs.

How to Replace Template Text in a PowerPoint File?

import {
  findSlidePlaceholder,
  getSlides,
  loadPresentation,
  savePresentation,
  setShapeText,
} from '@office-kit/pptx';

const pres = await loadPresentation(existingPptxBytes);
const cover = getSlides(pres)[0]!;
const title = findSlidePlaceholder(cover, 'title');
if (title) setShapeText(title, 'Q3 Review');
const body = findSlidePlaceholder(cover, 'body');
if (body) setShapeText(body, 'Numbers up and to the right.');
const out: Uint8Array = await savePresentation(pres);

Author Decks from Scratch

With `createPresentation()`, you can build a complete PowerPoint deck from zero—no template required. The function returns a fully structured deck with a master, theme, and default layouts (`Blank`, `Title Slide`, `Title and Content`). You can then add slides, insert text boxes, images, tables, and charts using typed APIs. This approach gives full control over design and content, enabling programmatic generation of presentations for dashboards, reports, or AI-driven slide decks while maintaining ECMA-376 compliance.

How to Create a New PowerPoint Deck from Scratch?

import {
  addTitleSlide,
  createPresentation,
  savePresentation,
} from '@office-kit/pptx';

const pres = createPresentation();
addTitleSlide(pres, 'Q3 Business Review');
const out: Uint8Array = await savePresentation(pres);

Charts, Animations & Comments

@office-kit/pptx supports rich slide elements including charts (bar, line, pie, area), animations (fadeIn, fadeOut, appear), and comments. Charts embed live Excel data for editing in PowerPoint, while animations use preset effects with configurable durations. Comments let you add reviewer notes with author metadata and optional positioning. These features make the library suitable for creating interactive, data-rich presentations that meet professional standards and pass schema validation.

How to Add a Chart and Animation to a Slide?

import {
  addSlideChart,
  getSlides,
  loadPresentation,
  setShapeAnimation,
  savePresentation,
  inches,
} from '@office-kit/pptx';

const pres = await loadPresentation(templateBytes);
const slide = getSlides(pres)[0]!;
addSlideChart(slide!, {
  x: inches(0.5),
  y: inches(0.5),
  w: inches(8),
  h: inches(4.5),
  spec: {
    kind: 'column',
    categories: ['Q1', 'Q2', 'Q3', 'Q4'],
    series: [
      { name: 'Revenue', values: [120, 180, 240, 300] },
      { name: 'Cost', values: [80, 90, 130, 160] },
    ],
    title: 'FY26 plan',
  },
});
const shape = getSlideShapes(slide)[0]!;
setShapeAnimation(shape, { effect: 'fadeIn', durationMs: 800 });
await savePresentation(pres);

Validation & Schema Compliance

Ensuring PPTX files are ECMA-376 compliant is critical for compatibility across tools. @office-kit/pptx includes `validatePresentation()` to detect issues like missing relationships, invalid slide IDs, or broken layout references. It also uses `xmllint` in CI where available to validate generated XML against official schemas. This validation layer helps catch subtle errors before distribution, ensuring presentations open reliably in PowerPoint, Keynote, Google Slides, and LibreOffice—without relying on "open and pray" behavior.

How to Validate a PowerPoint Presentation?

import { validatePresentation } from '@office-kit/pptx';

const issues = validatePresentation(pres);
for (const i of issues) console.error(i.severity, i.message);
// Catches missing rels, dangling slide ids, layouts without masters, etc.
 English