Browse modulesReportsFunctions
Function: render()
function render(tree: Node, options: RenderOptions): Promise<RenderResult>;Defined in: server/reports/index.ts:118
Render a document tree to a buffer in the specified format.
Build the tree with JSX templates, then pass it here:
Parameters
| Parameter | Type | Description |
|---|---|---|
tree | Node | The root AST node to render, typically produced by a JSX template wrapped in Document and Page components. |
options | RenderOptions | Rendering options. |
Returns
Promise<RenderResult>
A promise that resolves to a RenderResult containing:
buffer— The compiled document as aBuffer.mimeType— MIME type for the output (e.g."application/pdf").metadata.pageCount— Number of pages in the rendered document.metadata.format— The format that was rendered.metadata.generatedAt— Timestamp of when the document was generated.warnings— Non-fatal issues encountered during compilation (e.g. unsupported features in DOCX output).
Example
import {
Document, Page, Heading, Text, VStack, render,
} from "@the-kaizen-labs/taproot/reports";
function Invoice(data: { title: string }) {
return (
<Document>
<Page>
<VStack gap={12}>
<Heading level={1}>{data.title}</Heading>
<Text>Hello, world.</Text>
</VStack>
</Page>
</Document>
);
}
const tree = Invoice({ title: "My Invoice" });
const { buffer, mimeType } = await render(tree, { format: "pdf" });Throws
When the tree fails validation (e.g. missing pages, unknown node types, invalid heading depth) or compilation fails.
Remarks
Report templates use a non-DOM JSX runtime. Name each template *.report.tsx
and start the file with
/** @jsxImportSource @the-kaizen-labs/taproot/reports */.
oxlint leaves the react / react-hooks / jsx-a11y plugins off by default,
so report files need no special lint handling; if your repo enables them,
scope them off the **/*.report.{tsx,jsx} glob. See the reports package README.