Document generation as an API
One template. Three formats. A signed download URL by the time you finish the curl.
POST an HTML+Twig template and the data to merge into it. Get back HTML, a Chromium-rendered PDF, and a Word DOCX — all from the same source, all behind signed URLs that expire on the schedule you set.
1. Author a template
curl -X POST https://api.docgen.philiprehberger.com/v1/templates \
-H 'Authorization: Bearer docgen_live_…' \
-H 'Content-Type: application/json' \
-d '{
"name": "Invoice",
"body": "<h1>Invoice {{ number }}</h1><p>{{ total }}</p>"
}'HTML + Twig source. The API parses the body, validates the syntax, and tells you which merge fields it found.
2. Freeze a version
curl -X POST https://api.docgen.philiprehberger.com/v1/templates/<id>/versions \
-H 'Authorization: Bearer docgen_live_…'Snapshots the current draft as v1. Versions are immutable — even if the draft changes, the version body never does.
3. Submit a render
curl -X POST https://api.docgen.philiprehberger.com/v1/renders \
-H 'Authorization: Bearer docgen_live_…' \
-H 'Content-Type: application/json' \
-d '{
"template_id": "<id>",
"formats": ["pdf", "docx"],
"data": { "number": "INV-001", "total": "$2,625.00" }
}'Returns 202 + a poll URL. Add ?sync=true to block up to 15 seconds for small renders.
4. Download the output
{
"status": "succeeded",
"outputs": [
{
"format": "pdf",
"url": "https://api.docgen.philiprehberger.com/v1/renders/01.../outputs/pdf?signature=…",
"expires_at": "2026-06-07T22:30:00Z",
"bytes": 12480
}
]
}Signed URL, TTL you set, no auth header needed on the download. Pass it to your client, your CDN, your email.
What it actually ships
Twig templates
Sandboxed evaluation. The API walks the AST and tells you the merge-field schema before you submit data.
Frozen versions
Once a template version has rendered anything, the body is immutable. Last month's invoices don't change when this month's template ships.
Async + sync
POST /v1/renders returns 202 by default; ?sync=true blocks up to 15s. Same endpoint, two shapes.
Signed downloads
Output URLs are temporarySignedRoute with a configurable TTL. No public buckets, no auth headers on the link.
PDF via Chromium
Spatie/Browsershot + puppeteer. Best CSS fidelity available without firing up a print server.
DOCX via PhpWord
Native Word 2007 output. Honest tradeoffs documented.
Try it from the docs
The interactive reference mints a 30-minute sandbox key for your IP, pre-loads three reference templates, and lets you fire real renders against the live API. Paste your own JSON; watch the PDF appear in the next pane.
Open the try-it console →