A production ready PDF generation service powered by Gotenberg, with API key authentication via Caddy.
This setup provides:
- Gotenberg — Converts HTML, URLs, and Office files to PDF using headless Chromium
- Caddy — Reverse proxy handling SSL termination and API key authentication
- Clone this repo
- Update
Caddyfilewith your domain - Add your API keys to
api_keys.caddy - Start the containers:
docker compose up -dCaddy automatically provisions SSL certificates via Let's Encrypt.
Add or remove keys in api_keys.caddy:
map {header.X-Api-Key} {is_authorized} {
"your-api-key-here" "true"
"another-api-key" "true"
default "false"
}
You can generate secure keys using this:
openssl rand -hex 16After updating, hot reload Caddy without downtime:
docker compose exec caddy caddy reload --config /etc/caddy/CaddyfileUpdate the domain in Caddyfile:
pdf.example.com {
# ...
}
Send requests with your API key in the X-Api-Key header:
# Health check
curl https://pdf.example.com/health
# Generate PDF from HTML
curl -X POST \
-H "X-Api-Key: your-api-key-here" \
-F "files=@index.html;filename=index.html" \
https://pdf.example.com/forms/chromium/convert/html \
-o output.pdfSee Gotenberg documentation for all available endpoints.
Use the official gotenberg-php package to integrate with your PHP application:
composer require gotenberg/gotenberg-phpFor API key authentication, add a custom HTTP client that includes the X-Api-Key header with each request.
Default limits in docker-compose.yml:
| Service | Memory | CPU |
|---|---|---|
| Caddy | 256MB | - |
| Gotenberg | 2GB | 2 |
Adjust based on your workload.
- LibreOffice routes are disabled by default. Enable in
docker-compose.ymlif you need Office file conversion. - Gotenberg is not exposed directly—all traffic goes through Caddy.