Template to PDF
Generate PDFs from pre-built templates with dynamic data.
Template to PDF
Generate PDFs from pre-built templates by providing dynamic data. Perfect for invoices, receipts, certificates, and other structured documents.
POST
/v1/pdf/template
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
template | string | Yes | Template ID to use |
data | object | Yes | Dynamic data to populate the template |
options | object | No | PDF generation options |
Options Object
| Parameter | Type | Default | Description |
|---|---|---|---|
format | string | Template default | Paper format |
landscape | boolean | Template default | Orientation |
margin | object | Template default | Page margins |
Code Examples
curl -X POST https://api.pdfapi.dev/v1/pdf/template \
-H "Authorization: Bearer sk_live_xxx" \
-H "Content-Type: application/json" \
-d '{
"template": "invoice",
"data": {
"invoice_number": "INV-2025-001",
"date": "2025-01-18",
"due_date": "2025-02-18",
"customer": {
"name": "Acme Corp",
"email": "billing@acme.com",
"address": "123 Business St, Suite 100"
},
"items": [
{"description": "Widget Pro", "quantity": 2, "unit_price": 29.99},
{"description": "Gadget Plus", "quantity": 1, "unit_price": 49.99}
],
"subtotal": 109.97,
"tax": 9.90,
"total": 119.87
}
}' \
--output invoice.pdf
const response = await fetch('https://api.pdfapi.dev/v1/pdf/template', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.PDFAPI_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
template: 'invoice',
data: {
invoice_number: 'INV-2025-001',
date: '2025-01-18',
due_date: '2025-02-18',
customer: {
name: 'Acme Corp',
email: 'billing@acme.com',
address: '123 Business St, Suite 100'
},
items: [
{ description: 'Widget Pro', quantity: 2, unit_price: 29.99 },
{ description: 'Gadget Plus', quantity: 1, unit_price: 49.99 }
],
subtotal: 109.97,
tax: 9.90,
total: 119.87
}
}),
});
const buffer = await response.arrayBuffer();
import requests
import os
response = requests.post(
'https://api.pdfapi.dev/v1/pdf/template',
headers={
'Authorization': f'Bearer {os.environ["PDFAPI_KEY"]}',
'Content-Type': 'application/json',
},
json={
'template': 'invoice',
'data': {
'invoice_number': 'INV-2025-001',
'date': '2025-01-18',
'due_date': '2025-02-18',
'customer': {
'name': 'Acme Corp',
'email': 'billing@acme.com',
'address': '123 Business St, Suite 100'
},
'items': [
{'description': 'Widget Pro', 'quantity': 2, 'unit_price': 29.99},
{'description': 'Gadget Plus', 'quantity': 1, 'unit_price': 49.99}
],
'subtotal': 109.97,
'tax': 9.90,
'total': 119.87
}
}
)
with open('invoice.pdf', 'wb') as f:
f.write(response.content)
package main
import (
"bytes"
"encoding/json"
"io"
"net/http"
"os"
)
type InvoiceData struct {
Template string `json:"template"`
Data map[string]interface{} `json:"data"`
}
func main() {
payload := InvoiceData{
Template: "invoice",
Data: map[string]interface{}{
"invoice_number": "INV-2025-001",
"date": "2025-01-18",
"customer": map[string]string{
"name": "Acme Corp",
"email": "billing@acme.com",
},
"items": []map[string]interface{}{
{"description": "Widget Pro", "quantity": 2, "unit_price": 29.99},
},
"total": 119.87,
},
}
body, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", "https://api.pdfapi.dev/v1/pdf/template", bytes.NewBuffer(body))
req.Header.Set("Authorization", "Bearer "+os.Getenv("PDFAPI_KEY"))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
pdf, _ := io.ReadAll(resp.Body)
os.WriteFile("invoice.pdf", pdf, 0644)
}
Available Templates
| Template ID | Description | Required Fields | Availability |
|---|---|---|---|
invoice | Professional invoice | invoice_number, customer, items, total | Pro+ |
receipt | Payment receipt | receipt_number, items, total | Pro+ |
certificate | Achievement certificate | recipient, title, date | Business+ |
contract | Business contract | parties, terms, date | Business+ |
quote | Price quote | quote_number, customer, items | Pro+ |
Use the List Templates endpoint to get all available templates.
Template: Invoice
Required Fields
| Field | Type | Description |
|---|---|---|
invoice_number | string | Unique invoice identifier |
date | string | Invoice date (YYYY-MM-DD) |
customer | object | Customer details |
items | array | Line items |
total | number | Total amount |
Customer Object
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Customer name |
email | string | No | Customer email |
address | string | No | Billing address |
phone | string | No | Phone number |
Item Object
| Field | Type | Required | Description |
|---|---|---|---|
description | string | Yes | Item description |
quantity | number | Yes | Quantity |
unit_price | number | Yes | Price per unit |
Optional Fields
| Field | Type | Description |
|---|---|---|
due_date | string | Payment due date |
subtotal | number | Subtotal before tax |
tax | number | Tax amount |
tax_rate | number | Tax rate percentage |
discount | number | Discount amount |
notes | string | Additional notes |
payment_terms | string | Payment terms |
logo_url | string | Company logo URL |
Template: Receipt
Required Fields
| Field | Type | Description |
|---|---|---|
receipt_number | string | Receipt identifier |
date | string | Transaction date |
items | array | Purchased items |
total | number | Total paid |
payment_method | string | Payment method used |
Template: Certificate
Required Fields
| Field | Type | Description |
|---|---|---|
recipient | string | Recipient name |
title | string | Certificate title |
description | string | Achievement description |
date | string | Issue date |
Optional Fields
| Field | Type | Description |
|---|---|---|
issuer | string | Issuing organization |
signature_url | string | Signature image URL |
badge_url | string | Badge/seal image URL |
certificate_id | string | Certificate ID |
Response
Success (200)
Content-Type: application/pdf
Content-Disposition: attachment; filename="document.pdf"
Error Responses
Missing Required Field (400)
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Missing required field: customer.name"
}
}
Template Not Found (404)
{
"error": {
"code": "NOT_FOUND",
"message": "Template 'custom-invoice' not found"
}
}
Template Not Available (403)
{
"error": {
"code": "TEMPLATE_NOT_AVAILABLE",
"message": "Template 'contract' requires a Business plan or higher"
}
}
Template Rendering Failed (500)
{
"error": {
"code": "TEMPLATE_ERROR",
"message": "Failed to render template",
"details": {
"reason": "Invalid date format for field 'date'"
}
}
}