Ream
Read Word, Excel, PowerPoint and PDF — and convert any of them to PDF, SVG, HTML, Markdown, DOCX or XLSX. From scratch, in the browser. No LibreOffice, no headless Office, no commercial SDK.
Ream parses seven document formats — the modern Office Open XML trio (.docx,
.xlsx, .pptx), .pdf, and the legacy binary .doc / .xls / .ppt — into one
format-neutral interlayer, then renders that to PDF, SVG, HTML, Markdown, DOCX or XLSX.
It is implemented directly from the ECMA-376 (OOXML), ISO 32000 / 19005
(PDF / PDF/A), and Microsoft's binary-format specifications — no wrapper around
LibreOffice, headless Office, or any commercial SDK. Pure TypeScript/JavaScript on
Uint8Array in and Uint8Array out, so the same code runs unchanged in the browser,
Node.js, serverless and edge runtimes.
| |
|---|
| Reads | .docx · .xlsx · .pptx · .pdf · legacy .doc · .xls · .ppt |
| Writes | .pdf (incl. PDF/A-1/2/3, PDF/UA-1, signed, encrypted) · .svg · .html · .md · .docx · .xlsx |
Install
npm install reamkit
Runtime dependencies are minimal: fflate (ZIP/Deflate) and fast-xml-parser.
Usage
Parse once into the format-neutral interlayer, convert to any target. The
format is sniffed from the bytes; no fonts to wire up — an open
metric-compatible substitute font (Arimo for sans, Tinos for serif, Cousine for
monospace, plus Carlito/Caladea for Calibri/Cambria — the same families LibreOffice
substitutes, with Cambria's Cyrillic and Greek from Noto Serif) is fetched
automatically based on the document's referenced fonts,
with a Noto face for the Japanese, Korean, Chinese, Arabic, Hebrew, Thai or
Indic (Hindi, Bengali, Tamil and six more scripts) text the document holds:
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, pdf, doc, xls or ppt — 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 md = await doc.convert('md'); // GitHub-Flavored Markdown — same, narrower
const docx = await doc.convert('docx'); // write WordprocessingML back out
const xlsx = await doc.convert('xlsx'); // write SpreadsheetML back (xlsx source)
// Hand the bytes to the browser: preview, download, upload, …
const url = URL.createObjectURL(new Blob([pdf], { type: 'application/pdf' }));
window.open(url);
doc.flow exposes the parsed document tree, doc.format the detected format,
and doc.convertWithReport(...) returns { bytes, losses } (pass
strict: true to throw on the first conversion loss instead). Input/output
are plain Uint8Arrays, so wiring this to files, the network, or disk is up
to you.
An encrypted source opens with its password — a PDF's user or owner password,
or an Office package's (MS-OFFCRYPTO, Agile and Standard). A wrong one, or none
where one is needed, throws WrongPasswordError:
const doc = Ream.parse(bytes, { password: 'secret' });
Bring your own fonts (no network)
To embed specific fonts — or to avoid the network entirely — pass the font
bytes in. convert then does 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())),
// italic, boldItalic — optional; missing faces degrade gracefully
};
const pdf = await Ream.parse(bytes).convert('pdf', { fonts });
Font resolution chain
For finer control, chain font providers. The chain is asked for the
document's default faces, then for each family the document names, then for
the face of each writing system its text holds; the first provider to answer a
request wins it. A remote or local winner is recorded as a substituted loss
in the report:
import { Ream, localFontProvider, remoteFontProvider } from 'reamkit';
const pdf = await doc.convert('pdf', {
fontProviders: [
localFontProvider(), // the family installed on this machine (Chromium Local
// Font Access; embedding-restricted fonts are never used)
remoteFontProvider(), // else its open substitute from the CDN
],
});