Install
Package and versions
The separate @silurus/ooxml-opendocument package adds experimental reading of
OpenDocument presentations, text documents and spreadsheets. Each reader maps the package
directly into the existing PPTX slide, DOCX document or XLSX workbook model; the ordinary
layout and Canvas renderers draw it. No intermediate OOXML package is generated.
npm i @silurus/ooxml @silurus/ooxml-opendocumentThe package versions must match exactly. The add-on pins its @silurus/ooxml peer
to the same version; upgrade both together. A stale runtime or model-source protocol fails
before input loading with CompanionRuntimeMismatchError
(code: 'companion-runtime-mismatch').
Applications that do not opt in need no change. Ordinary viewer imports do not import, fetch or initialize an OpenDocument reader.
Browser viewers
Reader options by format
Import a reader and pass it as its own option: { odp } to the PPTX viewers
and loaders, { odt } to the DOCX ones and { ods } to the
XLSX ones. Each reader enables its own family only. OOXML input passed to the same viewer
continues through the ordinary parser.
| Input | Entry | Reader / factory | Loaders and viewers |
|---|---|---|---|
| ODP, OTP | @silurus/ooxml-opendocument/odp | odp / createOdp() | PptxViewer, PptxScrollViewer, PptxPresentation.load, openPptxPresentation, materializePptxPresentation |
| ODT, OTT | @silurus/ooxml-opendocument/odt | odt / createOdt() | DocxViewer, DocxScrollViewer, DocxDocument.load, openDocxDocument, materializeDocxDocument |
| ODS, OTS | @silurus/ooxml-opendocument/ods | ods / createOds() | XlsxViewer, XlsxWorkbook.load, openXlsxWorkbook, materializeXlsxWorkbook |
ODP → PPTX Viewer
import { PptxViewer } from '@silurus/ooxml/pptx';
import { odp } from '@silurus/ooxml-opendocument/odp';
const canvas = document.querySelector('#presentation') as HTMLCanvasElement;
const viewer = new PptxViewer(canvas, { odp });
await viewer.load(await file.arrayBuffer()); // .odp, .otp or .pptx
// When the preview is removed:
viewer.destroy();ODT → DOCX Viewer
import { DocxViewer } from '@silurus/ooxml/docx';
import { odt } from '@silurus/ooxml-opendocument/odt';
const canvas = document.querySelector('#document') as HTMLCanvasElement;
const viewer = new DocxViewer(canvas, { odt });
await viewer.load(await file.arrayBuffer()); // .odt, .ott or .docx
// When the preview is removed:
viewer.destroy();ODS → XLSX Viewer
import { XlsxViewer } from '@silurus/ooxml/xlsx';
import { ods } from '@silurus/ooxml-opendocument/ods';
const container = document.querySelector('#workbook') as HTMLElement;
const viewer = new XlsxViewer(container, { ods });
await viewer.load(await file.arrayBuffer()); // .ods, .ots or .xlsx
// When the preview is removed:
viewer.destroy();Node sessions
Readers in Node sessions
import { readFile } from 'node:fs/promises';
import { openPptxPresentation } from '@silurus/ooxml/node';
import { odp } from '@silurus/ooxml-opendocument/odp';
const session = await openPptxPresentation(await readFile('deck.odp'), { odp });
try {
for await (const slide of session.slides()) {
// Consume each ordinary slide model in your application.
}
} finally {
await session.close();
}openDocxDocument with { odt }, openXlsxWorkbook
with { ods } and the materialization APIs accept the readers the same way.
Close sessions in finally.
Assets and CSP
Asset loading
Importing an entry or calling its factory fetches nothing. When a matching file is opened, the parser Worker (or Node) imports the reader's self-contained ES source module and its WASM:
| Reader | Assets |
|---|---|
odp | odp-source-module.mjs, opendocument_odp_bg.wasm |
odt | odt-source-module.mjs, opendocument_odt_bg.wasm |
ods | ods-source-module.mjs, opendocument_ods_bg.wasm |
Serve these files with the other package assets and allow the source module URL in your
Content Security Policy for scripts and Worker imports. When an asset pipeline relocates the
files, create the reader with createOdp, createOdt or
createOds and absolute moduleUrl and wasmUrl options, and
pass it as the same option.
import { createOdp } from '@silurus/ooxml-opendocument/odp';
const odp = createOdp({
moduleUrl: new URL('/assets/odp-source-module.mjs', location.href).href,
wasmUrl: new URL('/assets/opendocument_odp_bg.wasm', location.href).href,
});
const viewer = new PptxViewer(canvas, { odp });Rendering policy
Rendering and rejection rules
The readers aim to render every OpenDocument feature they read. Each one is read as ODF 1.3 specifies and mapped onto the target model; where the specification leaves a choice to the consumer, or LibreOffice reads it differently, LibreOffice is the reference. Where the target model has no exact counterpart, a feature is drawn with its nearest equivalent instead of refusing the document, so a document may show differences from LibreOffice.
A few features are not drawn at all, and are listed as known differences in the full reference: for example section backgrounds, character shadows, outlines, reliefs and overlines in ODT, and dimension lines, regular polygons and form controls in ODS. Unsupported features never make a document reject.
A document is rejected only when it is corrupt, encrypted or unsafe, or when it exceeds a resource limit. The readers never execute scripts, macros or forms, and never fetch external resources: linked files outside the package are not drawn.
This differs from the experimental legacy DOC/XLS/PPT readers,
which currently reject the whole document with unsupported-content when they meet a
structure they cannot map (issue #2263).
A source claims a package only by its mimetype file, so admission inspects the bytes,
not the filename. Other inputs, including other OpenDocument families, continue on the OOXML
path unchanged. The ZIP is read with the same structural checks and inflation limits as OOXML
packages, including your resourceLimits.
Presentations
ODP features
The ODP reader maps a presentation into the PPTX slide model; LibreOffice Impress is the reference where ODF leaves a choice. It reads:
- Slides and master pages: master background objects; header, footer, date/time and page-number frames with the slide's display settings; slide and master backgrounds; hidden slides and speaker notes.
- Styles: the cascade of graphic and presentation styles, including per-level outline styles of outline placeholders; paragraph, text and list styles with indents, bullet characters, pictures and number labels.
- Shapes: custom shapes from their enhanced geometry (formulas, modifiers, every path command, text areas, mirroring), rectangles, ellipses and arcs, polygons and regular polygons, paths, lines, connectors, dimension lines (as their line), captions, groups, transforms and shape hyperlinks. Extruded custom shapes use the slide model's 3-D scene, and Fontwork shapes the matching DrawingML text warp.
- Fills and lines: solid fills, every gradient style with borders and multi-colour stops, uniform and gradient transparency, hatches as generated pictures, bitmaps stretched, tiled or placed once; dashes, caps, joins and markers; shadows, glow and soft edges.
- Text: fonts per script, sizes, weight, posture, colours including automatic colour, underline and strike-through, raised and lowered text, capitals, letter spacing, highlighting, outline and shadowed text, tabs, line breaks, fields and hyperlinks; paragraph alignment, indents, spacing, line height, tab stops, columns, anchoring, padding, wrapping and shrink-on-overflow.
- Pictures and objects: cropping, mirroring, colour modes, luminance and contrast, transparency; StarView metafile pictures (converted to SVG); embedded and OLE objects through their replacement pictures; tables with column widths, row heights, spans, cell fills, borders and templates.
- Charts:
office:chartobjects are read with their own data table into the shared chart model; a structurally invalid chart is drawn from its replacement picture.
Animations and transitions are not played. Text follows the fonts available to the browser, so text set in fonts LibreOffice substitutes can wrap differently. To serve the fonts a presentation uses, configure font sources.
Text and spreadsheets
ODT and ODS features
ODT maps into the DOCX document model: paragraphs, headings and fields, character
and paragraph properties, every list and outline numbering style, page styles with headers,
footers and columns, sections, footnotes and endnotes, tables, drawings, pictures and formula
objects, drawn as math when you also pass the opt-in math engine
(import { math } from '@silurus/ooxml/math', then { odt, math });
without it, formulas are skipped as OOXML equations are. Page number and page count are computed by the layout; other fields show
their stored value, and tracked changes show their accepted state.
ODS maps into the XLSX workbook model: tables as sheets, cell values and the cached value of formula cells (formulas are kept as text and never calculated), merged cells, cell and data styles, named ranges, validations, conditional formats, sparklines, pictures, shapes and embedded charts. Page layout, headers and footers are not shown, because the workbook viewer shows the grid rather than printed pages. Rows and columns beyond the workbook grid (1,048,576 rows and 16,384 columns) are not shown, as when LibreOffice saves such a table as a workbook.
Read the full feature lists, LibreOffice compatibility rules and known differences on GitHub →
Failures
Failures and limits
Once a reader claims a file, its failure rejects the load. There is no retry through another source or the OOXML parser.
- Encrypted packages reject with
OoxmlError,code === 'unsupported-encryption'. - Packages over the ZIP and package limits, including your
resourceLimits, reject withOoxmlResourceLimitError(code === 'ooxml-resource-limit'). - A document over the reader's memory or work budget, or over a count bound such as 10,000 slides or 8 million materialized cells, rejects with an error whose message names the limit. Many per-element bounds (for example nesting depth, gradient stops or shape formula work) clamp or drop only the content beyond them, without rejecting the document.
- A stale viewer/add-on combination fails before input loading with
companion-runtime-mismatch.
Branch on error.code, not on message text, and show other failures as a generic
“could not open this file” result.
Error delivery and application messages → · Full OpenDocument reference →