Design a template
Use the template designer to select text, paragraphs, a table row or a whole table and insert a binding. Define an outer repeat or condition before fields inside it. Repeated rows use each array item as their data context.
import { createTemplateEditor } from "@onodocs/editor";
const designer = createTemplateEditor({
container,
sampleData: { customer: "Willow Design", items: [{ name: "Review", price: 125 }] }
});
await designer.open(templateBytes);Supply an empty, sized host and template bytes. Preview opens generated content for ordinary editing; Back to template returns to the design. Download template saves the reusable source. Dispose the designer on unmount.
Generate from application data
import { openTemplate } from "@onodocs/sdk";
const template = await openTemplate(templateBytes);
try {
const bytes = await template.generate(data, { locale: "en-US" });
await storeDocument(bytes);
for await (const bytes of template.batch(records, { locale: "en-US" })) {
await storeDocument(bytes);
}
} finally {
template.dispose();
}templateBytes is your DOCX template, data is one record, records supplies batch records, and storeDocument is your storage callback. Each generation starts from the original template. Consume batch results incrementally. Pass a cancellation signal through generation options when needed.
Choose a binding
| Binding | Data and behavior |
|---|---|
| Text / number / date | A property path selects a value. Number/date options use Intl formatting; default locale is en-US and date time zone is UTC. |
| Image | PNG/JPEG bytes and media type, with width and height in points and an optional description. |
| Repeat | An array produces one copy per item; nested fields use the item context. |
| Condition | Truthy values or nonempty arrays retain the region. |
| Reusable section | Define named content once and include it with the current context or a selected subrecord. |
Bindings are stored in Word content-control tags. Paths are property-name arrays, not executable expressions. Missing data, incompatible types and recursive sections report errors. Removing a binding preserves the placeholder content. Reusable sections stay within their defining Word story part.
Refresh fields and export
Node generation refreshes supported sequence and bookmark-reference fields. Browser generation also lays out output for page numbers, page references and supported contents tables. Node callers needing page-dependent fields can supply a finalize callback that opens and saves through the server renderer.
Unsupported fields retain cached content. Use onFieldStatus for diagnostics, fields: "require-current" to reject unresolved output, or fields: "preserve" to retain caches. Locked fields keep authored values. Save DOTX/DOTM templates as DOCX before generation.
Open generated bytes in the editor for user adjustments, then export PDF. The proposal studio demonstrates business data, repeating fee rows and editable output.