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

ParameterTypeRequiredDescription
templatestringYesTemplate ID to use
dataobjectYesDynamic data to populate the template
optionsobjectNoPDF generation options

Options Object

ParameterTypeDefaultDescription
formatstringTemplate defaultPaper format
landscapebooleanTemplate defaultOrientation
marginobjectTemplate defaultPage 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 IDDescriptionRequired FieldsAvailability
invoiceProfessional invoiceinvoice_number, customer, items, totalPro+
receiptPayment receiptreceipt_number, items, totalPro+
certificateAchievement certificaterecipient, title, dateBusiness+
contractBusiness contractparties, terms, dateBusiness+
quotePrice quotequote_number, customer, itemsPro+

Use the List Templates endpoint to get all available templates.


Template: Invoice

Required Fields

FieldTypeDescription
invoice_numberstringUnique invoice identifier
datestringInvoice date (YYYY-MM-DD)
customerobjectCustomer details
itemsarrayLine items
totalnumberTotal amount

Customer Object

FieldTypeRequiredDescription
namestringYesCustomer name
emailstringNoCustomer email
addressstringNoBilling address
phonestringNoPhone number

Item Object

FieldTypeRequiredDescription
descriptionstringYesItem description
quantitynumberYesQuantity
unit_pricenumberYesPrice per unit

Optional Fields

FieldTypeDescription
due_datestringPayment due date
subtotalnumberSubtotal before tax
taxnumberTax amount
tax_ratenumberTax rate percentage
discountnumberDiscount amount
notesstringAdditional notes
payment_termsstringPayment terms
logo_urlstringCompany logo URL

Template: Receipt

Required Fields

FieldTypeDescription
receipt_numberstringReceipt identifier
datestringTransaction date
itemsarrayPurchased items
totalnumberTotal paid
payment_methodstringPayment method used

Template: Certificate

Required Fields

FieldTypeDescription
recipientstringRecipient name
titlestringCertificate title
descriptionstringAchievement description
datestringIssue date

Optional Fields

FieldTypeDescription
issuerstringIssuing organization
signature_urlstringSignature image URL
badge_urlstringBadge/seal image URL
certificate_idstringCertificate 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'"
    }
  }
}