Getting started
Ream converts Word (.docx) and Excel (.xlsx) documents to PDF, 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.
Install
Section titled “Install”The package is published as reamkit:
npm install reamkitRuntime dependencies are minimal: fflate (ZIP/Deflate) and fast-xml-parser.
Convert a document
Section titled “Convert a document”Parse once into the format-neutral interlayer, then convert to any target. The format (docx/xlsx) is sniffed from the bytes. No fonts to wire up — an open substitute (Roboto for sans, Tinos for serif, Cousine for monospace — 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 or xlsx — sniffedconst pdf = await doc.convert('pdf'); // async — fetches a font if neededconst svg = await doc.convert('svg'); // same parse, different target
// Hand the bytes to the browser: preview, download, upload, …const url = URL.createObjectURL(new Blob([pdf], { type: 'application/pdf' }));window.open(url);Bring your own fonts (no network)
Section titled “Bring your own fonts (no network)”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 });The document object
Section titled “The document object”const doc = Ream.parse(bytes);doc.format; // 'docx' | 'xlsx'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