For AI agents: the complete documentation index is available at /pptxgenjs-plus/llms.txt, the full documentation bundle is available at /pptxgenjs-plus/llms-full.txt, and this page is available as Markdown at /pptxgenjs-plus/usage-saving.md.

Saving Presentations

Several methods are available for generating a presentation.

  • All methods return a Promise

Saving as a File (writeFile)

Save the presentation as a PowerPoint .pptx file.

  • In browser-based apps, this triggers a download using the correct pptx MIME-type.
  • In Node.js, it saves to disk via the native fs module.

Write File Props (WriteFileProps)

OptionTypeDefaultDescription
compressionbooleanfalseapply zip compression (exports take longer but save significant space)
fileNamestring'Presentation.pptx'output filename

Write File Example

// For simple cases, you can omit `then`
pptx.writeFile({ fileName: 'Browser-PowerPoint-Demo.pptx' });

// Using Promise to determine when the file has actually completed generating
pptx.writeFile({ fileName: 'Browser-PowerPoint-Demo.pptx' });
    .then(fileName => {
        console.log(`created file: ${fileName}`);
    });

Generating Other Formats (write)

Generate the presentation in various formats (e.g., base64, arraybuffer) — useful for uploading to cloud storage or handling in-memory.

Write Props (WriteProps)

OptionTypeDefaultDescription
compressionbooleanfalseapply zip compression (exports take longer but save significant space)
outputTypestringblob'arraybuffer', 'base64', 'binarystring', 'blob', 'nodebuffer', 'uint8array'

Write Output Types

outputTypeDescription
blobDefault for browsers
arraybufferOften used with WebAssembly or binary tools
base64Useful for uploads to APIs like Google Drive
nodebufferUse in Node.js with fs.writeFile()

Write Example

pptx.write({ outputType: "base64" })
    .then((data) => {
        console.log("write as base64: Here are 0-100 chars of `data`:\n");
        console.log(data.substring(0, 100));
    })
    .catch((err) => {
        console.error(err);
    });

Streaming in Node.js (stream)

Returns the presentation as a binary string, suitable for streaming in HTTP responses or writing directly to disk in Node.js environments.

Stream Example

Stream the generated file in an HTTP response (shown here with Express):

import express from "express"
import pptxgen from "pptxgenjs-plus"

const app = express()

app.get("/download", async (req, res) => {
    const pptx = new pptxgen()
    pptx.addSlide().addText("Streamed with pptxgenjs", { x: 1, y: 1 })

    const data = await pptx.stream()
    res.writeHead(200, {
        "Content-disposition": "attachment;filename=Presentation.pptx",
        "Content-Length": data.length,
    })
    res.end(Buffer.from(data as string, "binary"))
})

app.listen(3000)

Saving Multiple Presentations

In the Browser

Each new presentation should use a fresh new PptxGenJS() instance to avoid reusing slides or metadata.

let pptx = null;

// Presentation 1:
pptx = new PptxGenJS();
pptx.addSlide().addText("Presentation 1", { x: 1, y: 1 });
pptx.writeFile({ fileName: "PptxGenJS-Browser-1" });

// Presentation 2:
pptx = new PptxGenJS();
pptx.addSlide().addText("Presentation 2", { x: 1, y: 1 });
pptx.writeFile({ fileName: "PptxGenJS-Browser-2" });

In Node.js

import pptxgen from "pptxgenjs-plus"

// Presentation 1:
let pptx = new pptxgen()
pptx.addSlide().addText("Presentation 1", { x: 1, y: 1 })
await pptx.writeFile({ fileName: "PptxGenJS-Node-1.pptx" })

// Presentation 2 — a fresh instance:
pptx = new pptxgen()
pptx.addSlide().addText("Presentation 2", { x: 1, y: 1 })
await pptx.writeFile({ fileName: "PptxGenJS-Node-2.pptx" })
import pptxgen from "pptxgenjs-plus";

// Presentation 1:
let pptx1 = new pptxgen();
pptx1.addSlide().addText("Presentation 1", { x: 1, y: 1 });
pptx1.writeFile({ fileName: "PptxGenJS-NodePres-1" });

// Presentation 2:
let pptx2 = new pptxgen();
pptx2.addSlide().addText("Presentation 2", { x: 1, y: 1 });
pptx2.writeFile({ fileName: "PptxGenJS-NodePres-2" });