Skip to Content
GuidesData Binding

Data Binding

Learn how to inject dynamic content into your PDF templates.

Overview

Data binding allows you to replace placeholders in your template with actual data when generating a PDF. This is how you create personalized invoices, certificates, reports, and more.

Defining Variables

In the template editor, use the syntax {{variable_name}} to create a placeholder:

Hello, {{customer_name}}! Your invoice total is {{amount}}.

Passing Data via API

When calling the API, pass your data as key-value pairs in the data object:

{ "template_id": "HMQywVpZxqAM", "data": { "customer_name": "John Doe", "amount": "$1,234.56" } }

The API will replace {{customer_name}} with “John Doe” and {{amount}} with “$1,234.56”.

Supported Data Types

TypeExampleNotes
String"John Doe"Plain text
Number1234.56Will be converted to string
Date"2026-01-04"Format as string
URL"https://example.com/image.png"For image sources

Best Practices

  1. Use descriptive names - customer_name is better than n1
  2. Document your variables - Keep a list of all variables used in each template
  3. Validate data - Ensure all required variables are provided before calling the API
  4. Handle missing data - Variables without matching data will remain as {{variable_name}}

Example: Invoice

Template Variables

  • {{invoice_number}} - Invoice identifier
  • {{customer_name}} - Customer’s full name
  • {{customer_address}} - Billing address
  • {{line_items}} - Table of products/services
  • {{subtotal}} - Sum before tax
  • {{tax}} - Tax amount
  • {{total}} - Final amount due
  • {{due_date}} - Payment due date

API Call

const response = await fetch('https://api.pdftemplateapi.com/v1/pdf/create', { method: 'POST', headers: { 'x-api-key': 'YOUR_API_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({ template_id: 'YOUR_INVOICE_TEMPLATE', data: { invoice_number: 'INV-2026-001', customer_name: 'Acme Corporation', customer_address: '123 Business St, Suite 100', subtotal: '$1,000.00', tax: '$100.00', total: '$1,100.00', due_date: 'January 15, 2026' } }) });
Last updated on