Configuration
Backend options​
Pass a backend option to render to control which WASM module is used:
import { render } from "docxio";
// Use the minimal 441 KB WASM (browser-optimized)
const bytes = await render(doc, { backend: "minimal" });
// Use the full 920 KB WASM (includes template engine, validator)
const bytes = await render(doc, { backend: "full" });
// Auto-detect (default) -- tries minimal, falls back to full
const bytes = await render(doc);
The "minimal" backend generates XML parts inside WASM and assembles the ZIP archive in JavaScript via @docxio/zip. The "full" backend does everything in Rust, including ZIP packaging, template patching, and validation.
Pre-initializing WASM​
By default, the WASM module is initialized lazily on the first render call. To avoid the cold-start delay, call initWasm() early:
import { initWasm } from "docxio";
// Call once at app startup
await initWasm();
This is useful in server environments where you want the first request to be fast.
Document metadata​
Set metadata on the <document> root element:
<document
creator="Jane Doe"
title="Q4 Report"
description="Quarterly financial report"
keywords="finance, report, Q4"
>
...
</document>
These values are written to the docProps/core.xml part of the .docx file.
Default styles​
By default, docxio includes a base set of Word styles (Normal, Heading1-6, etc.). To disable them:
<document useDefaultStyles={false}>
...
</document>
You can also provide custom style definitions:
<document styles={{
paragraphStyles: [
{
id: "CustomBody",
name: "Custom Body",
basedOn: "Normal",
spacing: { after: 200, line: 276, lineRule: "auto" },
runProps: { fontSize: 22, fontFamily: "Georgia" },
},
],
}}>
<section>
<paragraph style="CustomBody"><run>Styled paragraph</run></paragraph>
</section>
</document>
Themes​
Apply a built-in theme for consistent document-wide styling:
import { corporate } from "docxio";
<document theme={corporate}>
...
</document>
See Styles and Themes for details on built-in themes and creating custom ones.
WASM tree limits​
The WASM boundary enforces safety limits on the document tree:
| Limit | Value |
|---|---|
| Max sections | 1,000 |
| Max blocks | 100,000 |
| Max nesting depth | 64 |
| Max JSON size | 50 MB |
These limits prevent runaway memory usage in browser environments. Documents exceeding these limits will produce an error at render time.