Quickstart
Python
Prerequisites
- A PDF4.dev account — sign up free
- An API key from Settings
- Python 3.8+
1. Create a template
Go to the dashboard and click New template. Note the template ID or slug.
2. Render a PDF
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")pip install requests3. Use in Django / FastAPI
Store the API key in an environment variable and call the API from your view or endpoint:
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
- PDF format — page size, margins, custom dimensions
- API reference — full render endpoint docs