@inkoxide/render
The engine every front end renders with, and renderDocument for document trees you already have as JSON.
The Inkoxide engine for every front end: the native engine in Node (the
inkoxide package) or WebAssembly in a Web Worker in a
browser (@inkoxide/render/browser, with
@inkoxide/wasm), the bundled fonts and
hyphenation patterns, Font.register, image loading under its policies, and the passes that
settle page numbers.
To make PDFs, install the package of your framework instead; each brings this one with it:
| Framework | Package |
|---|---|
| React | @inkoxide/react |
| Vue | @inkoxide/vue |
| Svelte | @inkoxide/svelte |
| Angular | @inkoxide/angular |
Install this package on its own to render documents you already have as JSON (a stored
result.document, or one another program wrote), or to write a front end of your own.
Part of Inkoxide. Requires Node.js 22 or later; ES modules only.
npm install @inkoxide/render
Rendering a document
import { writeFile } from 'node:fs/promises';
import { renderDocument } from '@inkoxide/render';
const doc = {
version: 1,
fonts: [{ id: 'Inter-Regular', family: 'Inter' }],
pages: [
{
size: { width: 595.28, height: 841.89 },
margin: { top: 72, right: 72, bottom: 72, left: 72 },
children: [{ type: 'text', runs: [{ text: 'Hello, Inkoxide', font: 'Inter-Regular', size: 24 }] }],
},
],
};
const { pdf, pages } = await renderDocument(doc);
await writeFile('hello.pdf', pdf);
The bundled faces (Inter, Noto Sans, Roboto Mono) are registered under their families; the document follows the schema reference.
API
| Name | What it does |
|---|---|
renderDocument(doc, images?, opts?) | A document tree to { pdf, pages, engineMs }. Its images are ids: images and opts.images give their bytes. |
init() | Starts the engine, loads Tailwind when it is installed and the fonts added with Font.register. Every render calls it. In a browser it takes where the module and assets are (@inkoxide/render/browser). |
Font.register(…) | Adds fonts by family, from bytes, a file or a URL. |
countPages(pdf), version(), engineStatus() | The page count of a PDF; the engine and schema versions; what init loaded. |
RenderError | Every failure, with a code. |
createRenderer(frontEnd) | For a front end: the functions it exports, from how it builds a document tree (FrontEnd): in Node a NodeRenderer (renderToBuffer, renderToFile, renderToStream, generate, renderTree), in a browser a BrowserRenderer (renderToBuffer, renderToBlob, a web stream, generate). Their documentation is the front ends'. |
PdfRun, sameDocument, viewerUrl (@inkoxide/render/browser) | For a front end's browser helpers: a document rendered to a PDF blob and its URL (BlobRender renders it), again when it changes (follow) or on request, each render stopping the one still running and each URL revoked when another replaces it; whether two documents render the same PDF; and the URL a frame shows a PDF at, with or without the viewer's toolbar. PdfSnapshot is the state, and PdfState the state with update(), as the helpers give it. |
@inkoxide/render/templates | What templates served by id share in every front end: parseData, renderSettled, renderDocument. |
The guide describes the options, errors and limits, which are the same in every front end.
Licence
MIT. The bundled fonts are under the SIL Open Font License; their licences are in assets/fonts.
Synced from packages/render/README.md in the inkoxide repository.