Skip to main content

Render Functions

All render functions accept a docxio JSX document tree as the first argument.

render​

The primary render function. Returns a Uint8Array containing the .docx file bytes.

import { render } from "docxio";

const bytes: Uint8Array = await render(doc);
const bytes: Uint8Array = await render(doc, { backend: "minimal" });

Signature:

function render(
tree: DocumentNode,
options?: { backend?: "auto" | "minimal" | "full" }
): Promise<Uint8Array>;

renderToFile​

Renders and writes directly to disk. Available in Node.js, Bun, and Deno.

import { renderToFile } from "docxio";

await renderToFile(doc, "report.docx");

Signature:

function renderToFile(tree: DocumentNode, path: string): Promise<void>;

renderToBuffer​

Returns a Node.js Buffer.

import { renderToBuffer } from "docxio";

const buf: Buffer = await renderToBuffer(doc);

Signature:

function renderToBuffer(tree: DocumentNode): Promise<Buffer>;

renderToBlob​

Returns a browser Blob with the correct MIME type.

import { renderToBlob } from "docxio";

const blob: Blob = await renderToBlob(doc);
const url = URL.createObjectURL(blob);

Signature:

function renderToBlob(tree: DocumentNode): Promise<Blob>;

renderToReadableStream​

Returns a web ReadableStream<Uint8Array> for streaming HTTP responses.

import { renderToReadableStream } from "docxio";

const stream: ReadableStream<Uint8Array> = renderToReadableStream(doc);
return new Response(stream, {
headers: {
"Content-Type":
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
},
});

Signature:

function renderToReadableStream(tree: DocumentNode): ReadableStream<Uint8Array>;

See the Streaming guide for more examples.

renderToBase64​

Returns a base64-encoded string of the .docx bytes.

import { renderToBase64 } from "docxio";

const base64: string = await renderToBase64(doc);

Signature:

function renderToBase64(tree: DocumentNode): Promise<string>;

transformTree​

Transforms a JSX tree into the Rust-compatible format without rendering. Useful for debugging or inspecting the intermediate representation.

import { transformTree } from "docxio";

const transformed = transformTree(doc);
console.log(JSON.stringify(transformed, null, 2));

Signature:

function transformTree(tree: DocumentNode): DocumentNode;

initWasm​

Pre-initializes the WASM module. Call once at startup to avoid cold-start latency on the first render.

import { initWasm } from "docxio";

await initWasm();

Signature:

function initWasm(): Promise<void>;