PDF4.dev
Templates
POST
/api/v1/templates

Authorization

AuthorizationRequiredBearer <token>

API key from Settings page. Keys start with p4_live_ prefix.

In: header

Request Body

application/jsonRequired
nameRequiredstring

Template name. A slug is auto-generated from this.

htmlstring

HTML template content. Supports Handlebars {{variables}}.

pdf_formatobject

Page format configuration. If omitted, defaults to A4 portrait with 20mm top/bottom and 15mm left/right margins.

sample_dataobject

Default sample values for preview

header_component_idstring

Header component ID (comp_xxx)

footer_component_idstring

Footer component ID (comp_xxx)

curl -X POST "https://docs.pdf4.dev/api/proxy/api/v1/templates" \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Monthly Invoice",
    "html": "<!DOCTYPE html><html><body><h1>Invoice #{{invoice_number}}</h1><p>Amount: {{total}}</p></body></html>",
    "sample_data": {
      "invoice_number": "INV-001",
      "total": "$1,000.00"
    },
    "pdf_format": {
      "preset": "a4",
      "margins": {
        "top": "20mm",
        "bottom": "20mm",
        "left": "15mm",
        "right": "15mm"
      }
    }
  }'

Template created

{
  "id": "tmpl_a1b2c3d4e5f6",
  "name": "Invoice",
  "slug": "invoice",
  "html": "string",
  "plain_text": "string",
  "pdf_format": {
    "preset": "a4",
    "width": "210mm",
    "height": "297mm",
    "margins": {
      "top": "20mm",
      "bottom": "20mm",
      "left": "15mm",
      "right": "15mm"
    },
    "background_color": "#ffffff",
    "font_family": "Inter, sans-serif",
    "font_size": "14px",
    "text_align": "left",
    "horizontal_align": "left",
    "vertical_align": "top",
    "google_fonts_url": "https://fonts.googleapis.com/css2?family=Roboto&display=swap",
    "color": "#333333",
    "line_height": "1.5",
    "component_gap": "5mm",
    "footer_position": "after-content"
  },
  "sample_data": {},
  "header_component_id": "string",
  "footer_component_id": "string",
  "created_at": "2019-08-24T14:15:22Z",
  "updated_at": "2019-08-24T14:15:22Z"
}