Templates
Fill the gallery's templates, or the ones you design in the editor, with JSON.
# The template's own sample data is the shape it reads: take it, change what is yours (jq), print.
curl -s https://api.reflowpdf.com/v1/templates/invoice -H "Authorization: Bearer $REFLOWPDF_API_KEY" \
| jq '{data: (.sample_data | .invoice.number = "INV-1042" | .buyer.name = "Globex Corporation")}' \
| curl https://api.reflowpdf.com/v1/templates/invoice/pdf \
-H "Authorization: Bearer $REFLOWPDF_API_KEY" \
-H "Content-Type: application/json" \
-d @- -o INV-1042.pdf// The template's own sample data is the shape it reads: start from it, change what is yours.
const { sample_data } = await reflow.templates.get('invoice')
const pdf = await reflow.templates.pdf('invoice', {
data: { ...sample_data, invoice: { ...sample_data.invoice, number: 'INV-1042' }, buyer: { ...sample_data.buyer, name: 'Globex Corporation' } },
})
await writeFile(pdf.filename, pdf.bytes)# The template's own sample data is the shape it reads: start from it, change what is yours.
sample = client.templates.get("invoice").sample_data
data = {**sample, "invoice": {**sample["invoice"], "number": "INV-1042"}, "buyer": {**sample["buyer"], "name": "Globex Corporation"}}
pdf = client.templates.pdf("invoice", data=data)
pdf.save() # Invoice INV-1042.pdf (the template's <title>)Which templates#
- The gallery: 53 ready documents (invoices, quotes, contracts, reports, certificates, tickets…) with sample data. Their ids are stable:
invoice,purchase-order. See them all. - Yours: templates you saved in the editor's library (Save as template). Their ids start with
lib_. One made in the editor's Code view (HTML with{{ … }}and its data) is filled withdata; one designed on the page prints as designed (fillable: false).
curl "https://api.reflowpdf.com/v1/templates?q=invoice" -H "Authorization: Bearer $REFLOWPDF_API_KEY"for (const t of (await reflow.templates.list({ q: 'invoice' })).data) {
console.log(t.id, t.name, t.source)
}for t in client.templates.list(q="invoice").data:
print(t["id"], t["name"], t["source"])The shape of the data#
GET /v1/templates/{id} gives a template's source, its sample_data and its data_schema, a JSON Schema (2020-12) read from the sample. Validate your data against it, or generate types from it.
curl https://api.reflowpdf.com/v1/templates/invoice -H "Authorization: Bearer $REFLOWPDF_API_KEY"const t = await reflow.templates.get('invoice')
console.log(t.data_schema) // { type: 'object', properties: { invoice: …, items: … } }t = client.templates.get("invoice")
print(t["data_schema"])Leave data out and the template prints with its sample data: a quick way to see it. A value your data does not give prints empty and is reported (ReflowPDF-Missing-Variables).
Paper#
A template prints on its own paper (a gallery template's size and orientation, your template's page settings in the editor). options.paper is for a template that declares none.