PptxGenJS - Generate PowerPoint Presentations

4.0.1 · active · verified Sun Apr 19

PptxGenJS is a comprehensive JavaScript library designed for programmatically generating professional PowerPoint presentations (PPTX files) directly from various JavaScript environments, including Node.js, React, Angular, Vite, Electron, and modern web browsers. The library is currently at version 4.0.1 and maintains a fairly active release cadence, with minor and patch versions released every few weeks to months. It differentiates itself by allowing the creation of complex slides with text, tables, shapes, images, and charts without requiring a Microsoft PowerPoint installation or license. Key features include defining custom Slide Masters, supporting SVGs, animated GIFs, YouTube embeds, RTL text, and Asian fonts. It also offers a unique HTML to PowerPoint conversion for tables and provides full TypeScript definitions, ensuring a robust development experience. Presentations created are standards-compliant Open Office XML (OOXML) files compatible with major office suites like Microsoft PowerPoint, Apple Keynote, and LibreOffice Impress.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate PptxGenJS, define a slide master for branding, add a new slide using that master, then insert text and a basic table. Finally, it shows how to trigger a file download in a browser or logs a message for Node.js environments.

import PptxGenJS from 'pptxgenjs';

async function createPresentation() {
  let pptx = new PptxGenJS();
  
  // Define a Slide Master for consistent branding
  pptx.defineSlideMaster({
    title: 'MASTER_TITLE',
    bkgd: 'F1F1F1',
    objects: [
      { rect: { x: 0, y: 0, w: '100%', h: 0.75, fill: { color: 'E6E6E6' } } },
      { text: { text: 'PptxGenJS Demo', options: { x: 0.5, y: 0.25, w: 5, h: 0.5, fontSize: 24 } } },
      { image: { x: 9.5, y: 0.1, w: 0.75, h: 0.75, path: 'https://raw.githubusercontent.com/gitbrent/PptxGenJS/master/docs/assets/images/logo.png' } }
    ]
  });

  let slide = pptx.addSlide({ masterName: 'MASTER_TITLE' });

  slide.addText(
    'Hello PptxGenJS! This is a simple example.',
    { x: 0.5, y: 1.5, w: 12, h: 1, fontSize: 36, color: '363636', align: 'center' }
  );

  slide.addTable([
    [{ text: 'Header 1' }, { text: 'Header 2' }],
    ['Row 1, Cell 1', 'Row 1, Cell 2'],
    ['Row 2, Cell 1', 'Row 2, Cell 2']
  ], {
    x: 1, y: 3,
    w: 10, colW: [5, 5],
    border: { pt: 1, color: 'CCCCCC' },
    fill: 'F9F9F9',
    align: 'center',
    valign: 'middle'
  });

  // In a browser, this will trigger a download
  // In Node.js, you would typically use save() to write to a file system
  if (typeof window !== 'undefined') {
    pptx.writeFile({ fileName: 'MyPresentation.pptx' });
  } else {
    // Node.js example: save to a file
    // await pptx.writeFile({ fileName: 'MyPresentation.pptx' });
    console.log('Presentation generated. Run in browser to download.');
  }
}

createPresentation();

view raw JSON →