The whole integration
Nothing to compile, nothing to apt-get. res.content is the PDF.
import os
import requests
res = requests.post(
"https://api.filecook.com/render/pdf",
headers={"Authorization": f"Bearer {os.environ['FILECOOK_API_KEY']}"},
json={
"html": "<h1>Invoice #1042</h1>",
"options": {"format": "A4", "margin": "12mm"},
},
timeout=30,
)
res.raise_for_status()
with open("invoice.pdf", "wb") as f:
f.write(res.content)
Against the usual Python options
The two common libraries each have a sharp edge. wkhtmltopdf wraps a long-unmaintained WebKit build, so CSS Grid, Flexbox gaps, and modern selectors silently misrender. WeasyPrint is actively maintained and produces lovely output, but it implements its own layout engine — it does not execute JavaScript, so anything rendered client-side is simply absent.
- Filecook runs current Chromium, so charting libraries that draw in the browser work as-is
- No system packages to pin in your Dockerfile or CI image
- Identical output from a developer laptop, a CI runner, and production
Django and Celery
Render a template with render_to_string, hand the resulting HTML to the API, and return a FileResponse. For bulk exports, do the same inside a Celery task — the API is queue-backed on our side too, so fanning out a few hundred concurrent renders is expected rather than exceptional.
