Document Stack
Document Stack
Docs

Data Binding

Make your templates dynamic by connecting elements to data fields.

What is Data Binding?

Data binding connects your template elements to your application data. You set a field key on an element in the editor, then pass the actual value when generating a PDF. This is what makes templates reusable — design once, generate with different data every time.

How to Bind Data

  1. Select a Field or Image element on the canvas
  2. In the Inspector panel, find the Field Key input
  3. Enter a key name (e.g., customer_name, invoice_date)
  4. When you generate a PDF via the API, pass the matching key in your data:
JSON
{
  "templateId": "YOUR_TEMPLATE_ID",
  "data": {
    "customer_name": "Acme Corporation",
    "invoice_date": "February 8, 2026",
    "total_amount": "$4,500.00"
  }
}

Every element with a matching field key gets replaced with the value you provided.

Which Elements Support Data Binding?

ElementWhat Gets ReplacedData Type
FieldThe displayed textString
ImageThe image sourceURL or base64 string
TableThe table rowsArray of objects

Text Fields

The most common use case. You want a piece of text that changes per document:

  • Customer names and addresses
  • Invoice numbers, dates, amounts
  • Order IDs, tracking numbers
  • Any text content that varies

Dynamic Images

Set a field key on an Image element, then pass a URL or base64 string in your data:

JSON
{
  "data": {
    "company_logo": "https://yourcompany.com/logo.png",
    "signature": "data:image/png;base64,iVBORw0KGgo..."
  }
}
Image URLs must be publicly accessible from Document Stack's servers. For private images, use base64 encoding.

Table Data

Table elements accept an array of row objects. Each key in a row maps to a column in your table:

JSON
{
  "data": {
    "line_items": [
      { "description": "Design Services", "qty": "10", "rate": "$100", "total": "$1,000" },
      { "description": "Development", "qty": "20", "rate": "$150", "total": "$3,000" }
    ]
  }
}

See the Tables guide for full details.

Conditional Visibility

If a field key receives null, undefined, or an empty string, the element is automatically hidden in the generated PDF. This means you get conditional sections for free — just omit the data for elements you don't want to show.

Example

Have a "Discount" field? If you pass {"discount": "10% OFF"}, it shows. If you pass {"discount": null}, the element is hidden. No if statements needed!

Testing Your Bindings

Use the Preview button in the editor to test your data bindings. Enter sample JSON data and see it rendered in real-time before writing any API code.