Skip to content

Render a stored template ​

Use a template when the layout stays the same and only the values change: an invoice, a certificate, a receipt. The HTML lives on your account. Each call sends the template id and the new values, not the document again.

Sending raw HTML on every render is the other path. It is described in Render from HTML as source. That request carries the whole document, Base64-encoded, every time.

1. Mark the values that change ​

In the template HTML, wrap each value in {* DOP_… *}. The name has to start with DOP_.

html
<h1>Invoice {* DOP_number *}</h1>
<p>Billed to {* DOP_customer *}</p>
<p>Total: {* DOP_total *}</p>

Save the PDF options on the template itself (page size, margins, printBackground). The render call then stays a few lines long. The template id is shown in the dashboard. Creating and editing a template is covered in Create a template.

2. Send the id and the data ​

POST https://api.doppio.sh/v1/template/direct returns the PDF bytes.

js
import { writeFile } from 'node:fs/promises';

const response = await fetch('https://api.doppio.sh/v1/template/direct', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <YOUR API KEY>',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    templateId: '<YOUR TEMPLATE ID>',
    templateData: {
      DOP_number: '2026-1042',
      DOP_customer: 'Northwind',
      DOP_total: '€1,240.00',
    },
  }),
});

if (!response.ok) {
  throw new Error(`Doppio error ${response.status}: ${await response.text()}`);
}

await writeFile('invoice.pdf', Buffer.from(await response.arrayBuffer()));

templateData replaces each {* DOP_… *} tag. A string is inserted as text, so {* DOP_customer *} in the HTML becomes Northwind.

The same call with the official SDK:

js
import { writeFile } from 'node:fs/promises';
import { Doppio } from 'doppio-nodejs';

const client = new Doppio(process.env.DOPPIO_API_KEY);
const pdfBuffer = await client.renderTemplateDirect({
  templateId: '<YOUR TEMPLATE ID>',
  templateData: {
    DOP_number: '2026-1042',
    DOP_customer: 'Northwind',
    DOP_total: '€1,240.00',
  },
});

await writeFile('invoice.pdf', Buffer.from(pdfBuffer));

/v1/template/sync returns a JSON payload with a temporary documentUrl instead of the file bytes. The route does not say /pdf or /screenshot: that choice was saved with the template.

3. Pass an object or a list ​

An object or an array is not inserted as text. Doppio writes its JSON in place of the tag. Put {* DOP_lines *} in the HTML and the page shows the raw JSON. Put it in a script, with no quotes around it, and it is a JavaScript value.

json
{
  "templateId": "<YOUR TEMPLATE ID>",
  "templateData": {
    "DOP_customer": "Northwind",
    "DOP_lines": [
      { "name": "Widget", "qty": 2, "price": 12.5 },
      { "name": "Gadget", "qty": 1, "price": 40 }
    ]
  }
}
html
<p>Billed to {* DOP_customer *}</p>
<table id="lines"></table>
<script>
  const lines = {* DOP_lines *};

  const table = document.getElementById('lines');
  for (const line of lines) {
    const row = table.insertRow();
    row.insertCell().textContent = line.name;
    row.insertCell().textContent = String(line.qty);
    row.insertCell().textContent = String(line.price);
  }
</script>

The tag has to be written {* DOP_lines *}, with a single space on each side. After replacement the script is const lines = [{"name":"Widget","qty":2,"price":12.5}, …];. Quotes around the tag would turn that array into a string.

A string used inside JavaScript needs the quotes you would write for any string: const customer = "{* DOP_customer *}";. An object must not have them.

Doppio also sets window.doppioData to the whole templateData. A ' in any text value, as in O'Brien, breaks that script, so the tag above is the reliable way to read an object. A longer invoice built with Vue is in HTML Template example.

The editor preview does not run JavaScript. Use Real Doppio Render to see the rows.

4. Values that are easy to misread ​

Only a key present in templateData is replaced. If DOP_customer is missing from the call, the PDF still contains the characters {* DOP_customer *}. Default values saved in the dashboard are used by the editor preview. The API call does not read them, so send every value you want in the document.

A non-empty string is copied as is. <b>Northwind</b> is HTML, and the page renders it. In JavaScript the quotes are yours to write, so a " or a line break inside the value breaks const customer = "{* DOP_customer *}".

Every other value is inserted with JSON.stringify:

Value in templateDataWritten in place of the tag
"""", including the quote characters
00
falsefalse
nullnull
an object or an arrayits JSON, as in the previous section

A tag with the wrong spacing, such as {*DOP_customer*}, is not a key. It is left in the document, same as a missing key.

5. Produce many documents ​

When each document takes long enough that the caller should not wait, use POST /v1/template/async. The webhook is part of the template: save a doppio.webhook object in the template parameters, with the URL Doppio should call when the render finishes. The shape of that object is in Async params, and the flow is in A full ASYNC workflow.

A request can still override the template. A doppio.presignedUrl on the call uploads that one document to your bucket. See Upload to your S3 bucket.

All rights reserved