/reamkit:convert-documentsfrom reamkit
Converts Word, Excel, PowerPoint and PDF files (.docx, .xlsx, .pptx, .pdf, .doc, .xls, .ppt) to PDF, SVG, HTML, Markdown, DOCX or XLSX using reamkit in browser, Node.js, serverless or edge runtimes.
Ships in reamkit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
reamkit reads .docx, .xlsx, .pptx, .pdf, .doc, .xls and .ppt, and
writes PDF, SVG, HTML, Markdown, DOCX and XLSX. It is pure TypeScript over
Uint8Array: it never touches the file system, and it touches the network only
to fetch fonts for PDF and SVG output. Getting bytes in and out is the caller's
job.
npm install reamkit
The package is ESM-only (Node.js 20 or later, any modern browser, workers and
edge runtimes). From CommonJS, load it with await import('reamkit').
import { Ream } from 'reamkit';
declare const bytes: Uint8Array; // the document, however you obtained it
const doc = Ream.parse(bytes); // synchronous; the format is sniffed from the bytes
const pdf = await doc.convert('pdf'); // asynchronous; resolves to a Uint8Array
doc.format names the source ('docx' | 'xlsx' | 'pptx' | 'pdf' | 'doc' | 'xls' | 'ppt'),
doc.flow is the parsed format-neutral tree and doc.losses lists what the
reader could not take in.
| Target | Fonts and network | Source | What comes out |
|---|---|---|---|
'pdf' | yes, see below | any | Paginated PDF; for PDF/A, PDF/UA, signing or encryption load pdf-compliance |
'svg' | yes, see below | any | One SVG of the pages; a workbook as one picture per sheet |
'html' | none | any | Flowed HTML; a workbook as Excel's window shows it, one section per tab |
'md' | none | any | GitHub-Flavored Markdown; load documents-to-markdown for LLM input |
'docx' | none | any | A fresh, valid .docx with the formatting written as direct properties |
'xlsx' | none | .xlsx or .xls | The workbook's grid written back; any other source throws |
PDF and SVG need font bytes. Given none, Ream downloads open substitutes from
cdn.jsdelivr.net. When the runtime has no network access, a Content-Security-Policy
blocks that host, or the output must use particular typefaces, load the
supply-fonts skill before writing the call.
import { Ream } from 'reamkit';
const input = document.querySelector<HTMLInputElement>('input[type=file]')!;
input.addEventListener('change', async () => {
const file = input.files?.[0];
if (!file) return;
const bytes = new Uint8Array(await file.arrayBuffer());
const pdf = await Ream.parse(bytes).convert('pdf');
const url = URL.createObjectURL(new Blob([pdf], { type: 'application/pdf' }));
window.open(url);
});
import { readFile, writeFile } from 'node:fs/promises';
import { Ream } from 'reamkit';
const doc = Ream.parse(new Uint8Array(await readFile('report.docx')));
await writeFile('report.pdf', await doc.convert('pdf'));
await writeFile('report.html', await doc.convert('html'));
Ream.parse does the expensive reading. Keep the Ream instance and call
convert for every target instead of parsing again:
const doc = Ream.parse(bytes);
const [pdf, html, docx] = await Promise.all([
doc.convert('pdf'),
doc.convert('html'),
doc.convert('docx'),
]);
Every target resolves to bytes, HTML and Markdown included:
const html = new TextDecoder().decode(await doc.convert('html'));
The same password option opens an encrypted Office package (both MS-OFFCRYPTO
schemes) and a PDF (its user or owner password). A wrong password, or none where
one is needed, throws WrongPasswordError. isEncryptedPackage answers from
the bytes for an Office package only; a PDF has to be tried.
import { Ream, WrongPasswordError, isEncryptedPackage } from 'reamkit';
declare function askForPassword(): Promise<string>;
async function open(bytes: Uint8Array): Promise<Ream> {
// '' is the default: it opens a PDF that only restricts permissions.
let password = isEncryptedPackage(bytes) ? await askForPassword() : '';
for (;;) {
try {
return Ream.parse(bytes, { password });
} catch (error) {
if (!(error instanceof WrongPasswordError)) throw error; // corrupt or unsupported, not a password problem
password = await askForPassword();
}
}
}
The output of convert is never encrypted, whatever the source was. To keep a
PDF protected, encrypt it on the way out with encrypt (see pdf-compliance).
Nothing is dropped silently. convertWithReport returns the bytes with every
Loss ({ severity: 'dropped' | 'degraded' | 'substituted', feature, detail, where? }),
the reader's losses first. strict: true throws ConversionLossError on the
first loss instead.
import { ConversionLossError, Ream, formatLoss } from 'reamkit';
const { bytes: pdf, losses } = await Ream.parse(bytes).convertWithReport('pdf');
for (const loss of losses) console.warn(formatLoss(loss)); // "[dropped] text: …"
try {
await Ream.parse(bytes).convert('pdf', { strict: true });
} catch (error) {
if (error instanceof ConversionLossError) console.error(error.loss.detail);
else throw error;
}
Use strict where any loss must stop the flow (legal, archival). Markdown
reports everything it has no syntax for (a centred paragraph is enough), so
strict rejects many ordinary documents there; read the report instead.
Ream.parse accepts a PDF, rebuilds paragraphs, headings, lists, tables and
columns (from the structure tree when the PDF is tagged, from glyph positions
when not) and converts onward like any other source:
const doc = Ream.parse(pdfBytes);
const docx = await doc.convert('docx'); // editable Word document
const reading = doc.losses.find((l) => /read as a/u.test(l.detail)); // which reading the reader chose
The file decides how it is read: prose re-flows, while a form or a drawing is
kept as a page with every line where it stands, which gives DOCX, HTML and
Markdown no reading order or tables to work with. There is no OCR: a scanned
PDF gives text only where OCR software left a text layer. A PDF whose streams use
a filter Ream does not carry (such as BrotliDecode) needs a decoder passed as
Ream.parse(bytes, { filters: { BrotliDecode: (b) => decode(b) } }); without
one the loss report names the filter.
A password only decrypts the source; convert always writes in the clear. Do
not store or serve converted output where the encrypted original was the only
access control. Encrypt the PDF output with encrypt (pdf-compliance) or keep
it behind the same authorization. Source: docs/src/content/docs/guides/examples.md
("Decryption only").
Uint8ArrayReam.parse takes a Uint8Array. Wrap an ArrayBuffer
(new Uint8Array(await file.arrayBuffer()), new Uint8Array(await response.arrayBuffer()));
a Blob, File, Response, string or base64 text must be read into bytes
first. A Node.js Buffer is a Uint8Array and works as it is. A bare
ArrayBuffer fails with TypeError: bytes.subarray is not a function; bytes no
reader recognizes throw Unrecognized document format. Source:
Ream.parse in src/core/converter/ream.ts.
convert is asynchronousReam.parse is synchronous, convert and convertWithReport return promises,
for every target. Writing doc.convert('html') straight into a file or a
Blob without await stores a pending promise, not the document.
convert('xlsx') writes a spreadsheet's native grid and throws
convert('xlsx') requires a spreadsheet source; this document has no grid for a
.docx, .pptx, .pdf, .doc or .ppt. Check doc.format === 'xlsx' || doc.format === 'xls'
first. Source: Ream.convertWithReport in src/core/converter/ream.ts.
With no font option, PDF and SVG download substitute fonts and reject with
Failed to download font from https://cdn.jsdelivr.net/… when they cannot.
HTML, Markdown, DOCX and XLSX never fetch. Supply fonts as supply-fonts
describes for offline servers, sandboxes and strict CSPs.
The DOCX writer re-serializes the parsed document: valid and complete in content, but with resolved formatting as direct properties instead of the source's named styles. Use it to normalize or sanitize a document, not to edit its XML in place. XLSX → XLSX, by contrast, keeps the grid surface (cells, styles, merges, print model, conditional formats, tables, charts).
Ream reads the text a PDF carries. A page that is only a picture comes back as a picture with no words. Run OCR before Ream when scans are expected.
Ream where bundle size mattersReam pulls in every reader and writer. The per-format exports (readDocx,
readXlsx, writeHtml, writeMarkdown, writeDocx, writeSvg, createConverter)
keep unused formats out of a bundle, but they are @experimental and may change
in a minor release; prefer Ream unless the bundle budget forces otherwise.
doc.format is the format you expected for the input.%PDF-, a DOCX or XLSX with PK (a ZIP), SVG and HTML decode to markup.losses has been read or logged, or strict: true was used and passed.WrongPasswordError (ask for a
password), ConversionLossError (strict mode refused a loss; read .loss),
and a plain Error (unrecognized bytes, xlsx from a non-spreadsheet, or a
font download that failed).What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
document-conversion, file-format, reamkit, office-files, pdf-conversion
4 skills in this plugin
/documents-to-markdownUse when extracting the text of user-uploaded documents (Word, Excel, PowerPoint, PDF or legacy .doc, .xls, .ppt files) as Markdown with reamkit (Ream) for a language-model prompt, a chat attachment, retrieval/RAG or search indexing, or a docs site, including what to do with pictures, slides, sheets and scanned PDFs.
/pdf-complianceUse when producing archival PDF/A (1a/1b, 2a/2b/2u, 3a/3b/3u), accessible PDF/UA-1 or tagged PDF, digitally signed, password-encrypted or bookmarked PDF with reamkit (Ream), embedding the source file or other attachments, setting PDF metadata, or matching Word's or LibreOffice's pagination.
/supply-fontsUse when a reamkit (Ream) PDF or SVG conversion has to run without network access (offline, air-gapped, a serverless function without egress, a strict Content-Security-Policy), must use the organisation's own typefaces or the fonts installed on the user's machine, or comes out with empty boxes, the wrong typeface or a font loss in its report. Not needed for HTML, Markdown, DOCX or XLSX output, which use no fonts.
npx claudepluginhub alex-krassavin/reamkit --plugin reamkitOther plugins' skills for the same job