Skip to content

Getting started

Ream reads Word, Excel, PowerPoint and PDF — the modern .docx / .xlsx / .pptx / .pdf and the legacy binary .doc / .xls / .ppt — and converts any of them to PDF, SVG, HTML, DOCX or XLSX, implemented from the ECMA-376 and ISO 32000 specifications. It works on Uint8Array in and Uint8Array out, so the same code runs in the browser, Node.js, serverless and edge runtimes.

The package is published as reamkit:

Terminal window
npm install reamkit

Runtime dependencies are minimal: fflate (ZIP/Deflate) and fast-xml-parser.

Parse once into the format-neutral interlayer, then convert to any target. The format (docx/xlsx/pptx/pdf) is sniffed from the bytes. No fonts to wire up — an open metric-compatible substitute (Arimo for sans, Tinos for serif, Cousine for monospace, plus Carlito/Caladea for Calibri/Cambria — the same families LibreOffice substitutes) is fetched automatically based on the document’s referenced fonts:

import { Ream } from 'reamkit';
// e.g. from an <input type="file"> or a fetch() — anything that yields bytes.
const bytes = new Uint8Array(await file.arrayBuffer());
const doc = Ream.parse(bytes); // docx, xlsx, pptx or pdf — sniffed
const pdf = await doc.convert('pdf'); // async — fetches a font if needed
const svg = await doc.convert('svg'); // same parse, different target
const html = await doc.convert('html'); // flowed HTML — needs no fonts at all
const docx = await doc.convert('docx'); // WordprocessingML back out
const xlsx = await doc.convert('xlsx'); // SpreadsheetML back out (xlsx source)
// Hand the bytes to the browser: preview, download, upload, …
const url = URL.createObjectURL(new Blob([pdf], { type: 'application/pdf' }));
window.open(url);

To embed specific fonts — or to avoid the network entirely — pass the font bytes in. convert then performs zero I/O:

const fonts = {
regular: new Uint8Array(await fetch('/fonts/MyFont-Regular.ttf').then((r) => r.arrayBuffer())),
bold: new Uint8Array(await fetch('/fonts/MyFont-Bold.ttf').then((r) => r.arrayBuffer())),
};
const pdf = await Ream.parse(bytes).convert('pdf', { fonts });
const doc = Ream.parse(bytes);
doc.format; // 'docx' | 'xlsx' | 'pptx' | 'pdf'
doc.flow; // the parsed interlayer tree (paragraphs, tables, images, …)
doc.losses; // anything dropped/degraded while reading
const { bytes: out, losses } = await doc.convertWithReport('pdf', { fonts });
await doc.convert('pdf', { fonts, strict: true }); // throw on the first loss
  • Examples — PDF/A, signatures, font providers, SVG preview, recipes.
  • Concepts — the pipeline and the interlayer.