Renderer ReferenceLast updated on
Last updated on
Render artifacts to different output formats
Renderers transform Paradoc artifacts into output formats like text, PDF, and DOCX. Each renderer implements the ParadocRenderer interface, making it easy to build custom renderers for your specific needs.
Installation
@paradoc/core uses the unified renderer automatically. Install it directly
when building custom integrations or using format-specific functions:
npm install @paradoc/renderUsage
import { para } from '@paradoc/core'
// Create a form with a template layer
const form = para.form({
name: 'invoice',
fields: {
customer: { type: 'text', label: 'Customer' },
total: { type: 'money', label: 'Total' }
},
layers: {
text: {
kind: 'inline',
mimeType: 'text/plain',
text: 'Invoice for {{customer}}\nTotal: {{total}}'
}
},
defaultLayer: 'text'
})
// Fill the form with data
const filled = form.fill({
fields: {
customer: 'Acme Corp',
total: { amount: 1500, currency: 'USD' }
}
})
// Render the filled form
const output = await filled.render()
// output: "Invoice for Acme Corp\nTotal: $1,500.00"Use the optional renderer property to override the default for one call:
const output = await filled.render({ renderer: myRenderer })The same optional override is available to .seal({ renderer: myRenderer }).
Paradoc still applies its built-in PDF flattening and canonical hashing after
the custom renderer or conversion adapter returns.
Format Entry Points
renderLayer() is the default application entry point. Import a format subpath
when you need its low-level functions or format-specific configuration.
| Entry point | Description |
|---|---|
| Text | Deterministic text templating for HTML, Markdown, plain text |
| Fill PDF forms with AcroForm field support | |
| DOCX | Generate Word documents from templates |
renderLayer()
function renderLayer(options?: RenderLayerOptions): ParadocRenderer<
RendererLayer,
string | Uint8Array
>Renderer Interface
All renderers implement the ParadocRenderer interface. Use this to build custom renderers:
import type { ParadocRenderer, RenderRequest, RendererLayer } from '@paradoc/types'
const myRenderer: ParadocRenderer<RendererLayer, string> = {
id: 'my-renderer',
render(request: RenderRequest): string {
const { template, form, data, bindings, ctx } = request
// Your rendering logic here
return processTemplate(template.content, data)
}
}ParadocRenderer
RenderRequest
The request object passed to the render method:
RendererLayer
The resolved template content:
ParadocRendererContext
Optional context for customizing renderer behavior:
Building Custom Renderers
To create a custom renderer:
- Implement the
ParadocRendererinterface - Handle the template type(s) you support
- Use serializers for consistent value formatting
import type { ParadocRenderer, RenderRequest, RendererLayer } from '@paradoc/types'
// Custom CSV renderer example
export function csvRenderer(): ParadocRenderer<
RendererLayer & { type: 'text'; content: string },
string
> {
return {
id: 'csv',
render(request: RenderRequest) {
const { form, data } = request
// Generate CSV from form fields and data
const headers = Object.keys(form.fields || {})
const values = headers.map(key => {
const value = data.fields?.[key]
return value != null ? String(value) : ''
})
return [headers.join(','), values.join(',')].join('\n')
}
}
}Related
- Serialization - Value formatting for renderers
- Form Layers - Template layer configuration