Skip to content
Lamina PDF
0.9.0
GitHub
Open the web app

FlowTemplate

Defined in: packages/sdk/src/builder.ts:342

A laminapdf.document/1 template: a FlowDocument, with the same keys, in which a value can be a placeholder that Builder.flow fills from options.data.

  • { $data: "/invoice/number" } takes a value from the data, by JSON Pointer.
  • { $each: "/items", do: … }, in a list, adds do once per item of a list in the data; inside it, { $item: "/name" } takes a value from the current item.
  • { $if: "/paid", do: … }, in a list, adds do only when the value is there and isn’t false or null.

Placeholders nest. type, schema and profiles take none: profiles is read before filling, for new Builder({ profiles }).

const template: FlowTemplate = {
schema: "laminapdf.document/1",
styles: { body: { font: "Helvetica", size: 11 } },
blocks: [
{ type: "heading", level: 1, text: { $data: "/title" } },
{ $each: "/lines", do: { type: "paragraph", text: { $item: "/text" } } },
],
};
const data = { title: "Invoice 42", lines: [{ text: "Paper, 2 reams" }] };
builder.flow(template, { data });

0.2.0