Private betav0.1.0
Docs
Format developer documentation

Renderer API

API reference for the compiled renderer object.

Once you've bundled your documents using format compile or one of our bundler plugins, you can interface with it by importing it. What you import is called a renderer. You call it, generally with a blob of data to render down your bundle to HTML for the API.

import { invoice } from './_generated'

const doc = await invoice.render({ customerName: 'Ada Lovelace' })
import { invoice } from '@format:documents'

const doc = await invoice.render({ customerName: 'Ada Lovelace' })

The name of your document directory is converted to camelCase and used as the export name.

Directory nameImport name
invoiceinvoice
monthly-reportmonthlyReport
MonthlyReportmonthlyReport
monthlyReportmonthlyReport
tax-return-2025taxReturn2025

You can also use the default export to access all renderers:

import documents from './_generated'

const doc = await documents.invoice.render({ ... })
import documents from '@format:documents'

const doc = await documents.invoice.render({ ... })

Methods

NameDescription
Renders the document with the provided data and returns a FormatDocument.
Get a web stream of the assets ZIP attached to the renderer.
Returns the URL the renderer will use to locate the assets ZIP.
Sets the assets URL at runtime.
set ZipOptions at runtime.

Details

render

Description
Renders the document with the provided data and returns a FormatDocument.
Type
(data?: Record<string, unknown>) => Promise<FormatDocument>
Parameters
data
A JavaScript object passed to your document template with any arbitrary data.

getAssetsWebStream

Description
Returns a web stream to the assets ZIP.

If the assets ZIP was built at compile, bytes will be loaded from the filesystem. If using a runtime outside of Node, bytes will be loaded via fetch using the URL set with setAssetsUrl(). Otherwise, returns undefined.
Type
() => Promise<ReadableStream<Uint8Array> | undefined>

getAssetsUrl

Description
Returns the URL the renderer will use to locate the assets ZIP. On the node target this is auto-initialized to the local assets.zip. On browser and worker targets it returns undefined until setAssetsUrl is called.
Type
() => string | undefined

setAssetsUrl

Description
Sets the assets URL at runtime. Call this before render() when your assets ZIP is hosted on a CDN or object storage bucket.
Type
(url: string) => void

setZipOptions

Description
Sets options for a runtime ZIP build (dynamic asset mode). Call this before render(), e.g. to enable remoteAssets for documents that reference remote URLs. Has no effect if your ZIP was built at compile.
Type
(options: ZipOptions | undefined) => void
Was this page helpful?