Recipes
Render straight to a Buffer
import { renderPdfBuffer } from '@quik/pdf';
const buffer = await renderPdfBuffer('reports.summary', {
title: 'Q1 Summary',
rows: [ { label: 'Revenue', value: 1200 } ]
});
renderPdfBuffer initializes pdfmake's bundled VFS only when needed. If you already have a compiled document
definition, use renderPdfBufferFromDefinition(definition) instead of re-rendering a template.
Repeat rows in a table
content:
- type: table
body:
- [ "Label", "Value" ]
- type: repeat
items: "{{rows}}"
as: row
content:
- [ "{{row.label}}", "{{row.value}}" ]
empty:
- [ "No rows", "" ]
repeat also works outside table bodies, iterating items and binding each entry to the as (and optionally
indexAs) variable; empty content renders when the collection is empty.
Conditional content with when
content:
- type: when
test: '{{eq status "ok"}}'
then:
- type: text
value: "{{translate \"report.ok\"}}"
else:
- type: text
value: "Details disabled"
Apply preprocess hooks and a clone strategy
const docDefinition = renderPdfTemplate('reports.summary', data, {
clone: 'safe',
preprocess: [
(definition) => ({ ...definition, metadata: { generatedAt: new Date().toISOString() } })
],
debug: false
});
preprocess transforms run in order before compilation; clone is 'safe' (default, deep-clones the resolved
definition) or 'none'; debug: true logs template resolution and the inheritance chain.
Register or update a template programmatically
import { PdfTemplatesStore } from '@quik/pdf';
PdfTemplatesStore.set('reports.summary', { content: [] }, { replace: false });
PdfTemplatesStore.upsert('reports.summary', { content: [ { type: 'text', value: 'Updated' } ] });