Skip to content

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.

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) 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 — sniffed
const pdf = await doc.convert('pdf'); // async — fetches a font if needed
const 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);

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'
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.