Open in a new tab

Turn a plain-text outline into a PowerPoint deck (a title and bullets per slide), read every slide back, download it; a truncated archive gives the typed ParseError.

Uses @awacloud/ooxml (AGPL-3.0-only) over @awacloud/fw (Apache-2.0). This example's code is AGPL-3.0-only.

When to use it

A report, a meeting summary or a status page exported as slides people can open in PowerPoint, Keynote or LibreOffice Impress, built in the browser with nothing uploaded.

Copy-paste steps

  1. npm install @awacloud/ooxml (it depends on @awacloud/fw).
  2. Serve node_modules/@awacloud/fw/src/ and node_modules/@awacloud/ooxml/src/ at /vendor/fw/ and /vendor/ooxml/ (node serve.js from the examples root does this; any static server works).
  3. Copy index.html and main.js next to each other and open index.html through that server. The ../../_style/examples.css link is optional: copy that file along, or delete the link. Keep the legal notice under </main>: copy ../../LICENSES/AGPL-3.0-only.txt along, or point its link at your copy.

What it shows

  • pptx.write({ type: 'presentation', slides: [{ title, body }] }): the shorthand fills each slide's title and body placeholders; layouts, master and theme are generated when absent.
  • pptx.read(bytes) returns { presentation, package, unmodelledParts }; pptx.extractTitle(slide) and pptx.extractBody(slide) read the text back from the placeholders.
  • A file that is not a valid archive throws the typed ParseError (opc/invalid-zip): the page reports it instead of failing.
  • download.bytes with the PresentationML media type.
  • Not shown: pictures, tables, charts and transitions (the typed shapes model of each slide).

Code

main.js

javascriptAGPL-3.0-only67 lines

// SPDX-License-Identifier: AGPL-3.0-only
import { ModuleRuntime } from '@awacloud/fw/core/runtime.js';
import { download } from '@awacloud/fw/dom/fs/download.js';
import { fw_require, modules } from '@awacloud/ooxml';

const rt = new ModuleRuntime();
rt.registerAll([...fw_require, ...modules, download]);
const PPTX = rt.resolve('pptx');
const DOWNLOAD = rt.resolve('download');
const { ParseError } = rt.resolve('ooxmlErrors');

/** @typedef {{ title: string, body: string[] }} Slide */

/**
 * A plain-text outline to slides: a slide's first line is its title, the
 * lines after it are bullets (a leading `-` is dropped), a blank line ends it.
 * @param {string} outline @returns {Slide[]}
 */
export function parseOutline(outline) {
    return outline.split(/\n\s*\n/).map((block) => block.split('\n').map((l) => l.trim()).filter(Boolean))
        .filter((lines) => lines.length > 0)
        .map(([title, ...bullets]) => ({ title, body: bullets.map((b) => b.replace(/^-\s*/, '')) }));
}

/** The `.pptx` bytes: the shorthand `{ title, body }` fills a title and a body placeholder. @param {Slide[]} slides */
export const writeDeck = (slides) => PPTX.write({ type: 'presentation', slides });

/**
 * Read a deck back to titles and bullets, or the typed error of a bad file.
 * @param {Uint8Array} bytes @returns {{ ok: true, slides: Slide[] } | { ok: false, error: string }}
 */
export function readDeck(bytes) {
    try {
        const { presentation } = PPTX.read(bytes);
        // extractTitle / extractBody read the title and body placeholders of a slide.
        return { ok: true, slides: presentation.slides.map((/** @type {any} */ s) => ({
            title: PPTX.extractTitle(s), body: PPTX.extractBody(s),
        })) };
    } catch (err) {
        if (err instanceof ParseError) return { ok: false, error: `${err.code}: ${err.message}` };
        throw err;
    }
}

/** @param {string} id */
const el = (id) => /** @type {HTMLElement} */ (document.getElementById(id));
let deck = /** @type {Uint8Array | null} */ (null);

el('build').addEventListener('click', () => {
    deck = writeDeck(parseOutline(/** @type {HTMLTextAreaElement} */ (el('outline')).value));
    const result = readDeck(deck);
    if (!result.ok) {
        el('status').textContent = result.error;
        return;
    }
    el('status').textContent = `${deck.length} bytes, ${result.slides.length} slides`;
    el('slides').replaceChildren(...result.slides.map(({ title, body }) => {
        const li = document.createElement('li');
        li.textContent = `${title}: ${body.join(' · ')}`;
        return li;
    }));
    /** @type {HTMLButtonElement} */ (el('download')).disabled = false;
});
el('download').addEventListener('click', () => {
    const type = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
    if (deck) DOWNLOAD.bytes(deck, 'deck.pptx', type);
});

index.html

htmlAGPL-3.0-only45 lines

<!doctype html>
<!-- SPDX-License-Identifier: AGPL-3.0-only -->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>ooxml · An outline to a .pptx deck</title>
  <link rel="stylesheet" href="../../_style/examples.css">
  <script type="importmap">
  { "imports": {
    "@awacloud/fw": "/vendor/fw/main.js", "@awacloud/fw/": "/vendor/fw/",
    "@awacloud/ooxml": "/vendor/ooxml/main.js", "@awacloud/ooxml/": "/vendor/ooxml/" } }
  </script>
  <script type="module" src="./main.js"></script>
</head>
<body>
  <main>
    <h1>An outline to a .pptx deck</h1>
    <label for="outline">Outline: a title line, its bullets, a blank line between slides</label>
    <textarea id="outline" rows="8">Quarterly review
- Revenue up 12 %
- Two new markets

Next steps
- Hire
- Ship</textarea>
    <button id="build" type="button">Build and read back</button>
    <button id="download" type="button" disabled>Download deck.pptx</button>
    <p id="status" aria-live="polite"></p>
    <ol id="slides" aria-label="Slides read back"></ol>
  </main>
  <!-- aln:begin (AGPL-3.0 sections 0, 5d and 13; derived by _harness/contract.js legalNotice, checked by C7) -->
  <footer id="legal" aria-label="Legal notices">
    <p>Copyright (c) 2026 AwaCloud SAS. This page is free software under the GNU Affero General Public License,
      version 3 only (AGPL-3.0-only), with ABSOLUTELY NO WARRANTY:
      <a href="../../LICENSES/AGPL-3.0-only.txt">licence text</a>.</p>
    <p>It runs these packages, each with its own LICENSE and NOTICE file (third-party notices included):</p>
    <ul>
      <li>@awacloud/fw · Apache-2.0</li>
      <li>@awacloud/ooxml · AGPL-3.0-only</li>
    </ul>
  </footer>
  <!-- aln:end -->
</body>
</html>