PDF4.dev
Quickstart

Python

Prerequisites

1. Create a template

Go to the dashboard and click New template. Note the template ID or slug.

2. Render a PDF

render.py
import requests

response = requests.post(
    "https://pdf4.dev/api/v1/render",
    headers={"Authorization": "Bearer p4_live_your_key_here"},
    json={
        "template_id": "invoice",
        "data": {
            "company_name": "Acme Corp",
            "invoice_number": "INV-2025-001",
            "total": "$4,500.00",
        },
    },
)

if not response.ok:
    raise Exception(response.json()["error"]["message"])

with open("invoice.pdf", "wb") as f:
    f.write(response.content)

print("PDF saved to invoice.pdf")
Install requests
pip install requests

3. Use in Django / FastAPI

Store the API key in an environment variable and call the API from your view or endpoint:

views.py (Django)
import os
import requests
from django.http import HttpResponse

def generate_invoice(request):
    resp = requests.post(
        "https://pdf4.dev/api/v1/render",
        headers={"Authorization": f"Bearer {os.environ['PDF4_API_KEY']}"},
        json={"template_id": "invoice", "data": {"company_name": "Acme"}},
    )
    return HttpResponse(resp.content, content_type="application/pdf")

Next steps