Slides & PPTX
Folio opens PowerPoint decks as a document type of their own: masters, layouts and slides with placeholder inheritance, laid out by the same engine as documents, edited with the layered pages tools, exported back to .pptx without losing what Folio doesn't model, and to PDF.
| Package | For |
|---|---|
@nextgensoftwares/folio-slides | the deck model, inheritance, layout, PDF (DOM-free) |
@nextgensoftwares/folio-pptx | .pptx import and export (DOM-free) |
@nextgensoftwares/folio-plugin-slides | React viewer/editor: thumbnails, current slide, slide show |
Open a deck
import { importPptx, mediaBytes } from '@nextgensoftwares/folio-pptx';
const { presentation, package: source, warnings } = importPptx(new Uint8Array(await file.arrayBuffer()));presentation is plain JSON: store it, diff it, send it to a worker. source holds the original parts; keep it next to the presentation, export patches it. Pictures are media:ppt/media/… references: mediaBytes(source, src) returns their bytes. warnings lists what wasn't represented exactly (below).
For big decks, open the File in a worker instead (openPptxInWorker, see pptx): the file isn't held in memory, big pictures and media stay in it as Blobs (mediaBlob), and opening doesn't freeze the page. Save with exportPptxFile.
Or let the app do all of it: pptxFile() from plugin-slides owns the deck editor, the picture resolver and the opened package. Pass it to <SlidesApp file> and the app bar gets a File menu with Open… and Save as PowerPoint, and the title follows the file name:
import { SlidesApp, pptxFile } from '@nextgensoftwares/folio-plugin-slides';
const file = pptxFile({
// Optional: open in a worker (else on the main thread, still without holding the file).
worker: () => new Worker(new URL('@nextgensoftwares/folio-pptx/worker', import.meta.url), { type: 'module' }),
onOpen: (res) => registerFonts(res.fonts), // and show res.warnings
});
<SlidesApp file={file} measurer={fonts} metrics={(f) => fonts.metrics(f)} />;
// Or drive it yourself: await file.open(f); const bytes = await file.save();It loads @nextgensoftwares/folio-pptx on the first open or save, so install that package beside plugin-slides (an optional peer). Opening a file replaces the deck without an undo step, and each file gets its own picture resolver, so pictures from the previous deck never show.
Show and edit it
import { createDeckEditor } from '@nextgensoftwares/folio-slides-editor';
import { SlidesApp, createMediaResolver } from '@nextgensoftwares/folio-plugin-slides';
const media = createMediaResolver((src) => mediaBytes(source, src));
const editor = createDeckEditor({ presentation: deck });
editor.on('presentation', (s) => setDeck(s.presentation)); // autosave, export...
<SlidesApp
deck={editor}
measurer={fonts} // a FontEngine holding the deck's fonts (and register them with document.fonts)
metrics={(f) => fonts.metrics(f)}
resolveSrc={media.resolve}
title="Quarterly review"
/>;The app bar, toolbar (new slide with layouts, insert text box / shapes / picture / table, text formatting, arrange, present), thumbnails (multi-select, drag to reorder, slide menu), the slide, speaker notes, inspector tabs (Format, Slide, Notes, Selection, Design) and a status bar with the views: normal, slide sorter, outline, reading. Present (or F5) starts the show: →/Space/click forward, ←/Backspace back, Esc leaves, N toggles the notes; hidden slides are skipped.
On the slide: click to select, drag to move (with snapping), handles to resize and rotate, double-click to edit text, Delete, Ctrl/⌘+G to group; one undo history for slide and deck edits. Every change gives a new deck in which only what you touched changed (a moved placeholder gets its own position; bolding a word marks that run only). Empty placeholders show as dashed boxes while editing and never print. As in PowerPoint, a new shape's text sits in the middle (centred, in the shape's text style) and a text box's starts top-left; the caret in an empty shape starts where the text will go.
Every piece is public: see Building your own slides shell. A read-only viewer imports SlideDeck from @nextgensoftwares/folio-plugin-slides/viewer (no editor code). Without React, createDeckEditor runs the commands and createSlideEditor(deck, index, { measurer }) gives the slide editor (FolioView draws it) with apply(deck) to write back.
Save it
import { exportPptx } from '@nextgensoftwares/folio-pptx';
import { exportSlidesPdf } from '@nextgensoftwares/folio-slides/pdf';
const pptx = exportPptx(deck, { package: source }); // untouched slides, charts, animations: byte for byte
const pdf = await exportSlidesPdf(deck, { layout: { measurer: fonts }, fonts: fontBytes, images: (src) => mediaBytes(source, src) });A deck made in Folio (blankPresentation(), addSlide) exports without a package: a complete one is written.
A per-user watermark and viewer permissions, on a server (Node; no React or DOM):
import { watermarkPlugin } from '@nextgensoftwares/folio-reader';
import { exportSlidesPdf } from '@nextgensoftwares/folio-slides/pdf';
const pdf = await exportSlidesPdf(deck, {
layout: { measurer: engine }, shaper: engine, fonts: fontBytes, images,
plugins: [watermarkPlugin({ text: 'NID {{nid}}\n{{email}}' })],
variables: { nid: student.nid, email: student.email },
permissions: { print: true, copy: false },
});The watermark is drawn into every slide as vectors before the file is encrypted. The same pages also go through folio-reader's exportPagesPdf: exportPagesPdf(await layoutSlidesPdf(deck, { layout }), { pdf: { ...pdfOptions, painters: slidesPdfPainters }, plugins, variables }).
What is supported
| Area | Phase 1 |
|---|---|
| Structure | masters, layouts, slides, hidden slides, "hide background graphics", notes (read and written; the notes page layout read from the notes master: Notes Page view and PDF notes pages), handouts (the handout master read, edited in View › Handout Master: its header, date, footer and page number, background and own shapes, slides per page and orientation; patched, or written for new decks; PDF handouts with 1, 2, 3, 4, 6 or 9 slides per page), sections (p14:sectionLst, read, edited, written), slide size |
| Inheritance | placeholder position/geometry/fill/line/body props; text styles from presentation defaults, master title/body/other styles, master and layout placeholders, shape style font reference, own styles; colour map overrides |
| Text | runs (size, bold, italic, underline, strike, colour, highlight, fonts incl. theme fonts, caps, spacing, super/subscript, links, text outline, text shadow), paragraphs (alignment, indents and tab stops, both on the ruler, line and paragraph spacing, RTL), bullets (characters incl. every Wingdings, Wingdings 2/3 and Webdings slot through Unicode's mapping, and Symbol; auto-numbering, pictures), fields (slide number; date and time in PowerPoint's 13 formats, updated automatically), header and footer (date, footer, slide number placeholders), stored autofit scale (edited text shrinks further live on overflow), text columns, anchors, insets |
| Shapes | preset geometries (common ones exact, others approximated), custom geometry, solid/gradient (linear or radial, any stops)/picture fills, the 54 preset patterns (8×8 tiles, level on turned shapes; a Pattern fill editor with fore- and background colours), outlines with dash and arrowheads, outer shadows, soft edges, rotation and flips, connectors, groups |
| Pictures | PNG, JPEG, GIF, BMP, WebP, SVG; crop, Fill / Fit / Stretch in the frame, crop to shape; brightness, contrast, saturation, blur, transparency, grayscale. EMF/WMF drawn as vectors and text (folio-metafile; a host's convertImage comes first) |
| Audio, video | Start automatically, Loop until stopped, Hide while not playing (in the slide's timing) and Show Media Controls (presProps), read and written |
| Tables | columns, rows, spans, cell fills, borders, margins, anchors, table styles from tableStyles.xml |
| SmartArt | drawn from the drawing PowerPoint saves with every diagram (ppt/diagrams/drawingN.xml): real vector shapes and text, read-only (move or resize the whole diagram; its parts are exported untouched); the preview picture only when there is no drawing part |
| Charts | column, bar, line, area, pie, doughnut and radar charts drawn from their cached data; data edited and written back; Insert ▸ Chart adds new ones, written as real PowerPoint charts with their workbook |
| OLE | kept in the file; drawn from its preview picture, else a placeholder box |
| Transitions, animations | modelled (Slide.timing, Slide.transition), edited, written back and played with folio-slides-motion; the base Presenter alone fades in slides that have a transition |
Import diagnostics
interface ImportWarning {
code: WarningCode; // 'geometry-approx', 'chart-preview', 'image-format', 'animation-kept', ...
severity: 'info' | 'warning' | 'error';
message: string;
part?: string; slide?: number; shape?: { id: string; name?: string }; detail?: string;
count: number; // repeats merged
}Warnings carry no document text, so they can go to a host's telemetry as they are; summarizeWarnings(warnings) gives counts by code.
Fidelity
node tools/fidelity/slides/run.mjs (needs pnpm build, LibreOffice and poppler) renders synthetic decks, or any .pptx you pass, with LibreOffice Impress and with Folio, and reports per slide how many words match and how far they are, plus pixel diffs. Text lands within about a pixel of LibreOffice's placement. --perf 300 times a 300-slide deck end to end.