If you have ever built invoices, legal contracts, or multi-page reports in a serverless or Bubble.io app, you have probably hit the same two walls:
- Client-side canvas wrappers (
html2canvas/jsPDF) blur vector text, break CSS Flexbox/Grid, and slice table rows right in half across page breaks. - Serverless PDF APIs cold-start headless Chrome in 6–15 seconds, blowing past Bubble's hard 30-second server action timeout or costing $29–$59/month before you even launch.
We built DocEngine to solve both problems with a dual-engine, zero-retention architecture on Cloudflare Workers + Coolify Gotenberg.
Architecture Overview
Instead of forcing every document through one slow pipeline, we split rendering into three paths:
-
Warm Edge HTML → PDF (
~80mswarm /<1.6scold):- Uses Cloudflare's REST
/browser-rendering/pdfquick action as the primary engine with warm@cloudflare/puppeteer(keep_alive: 60_000) fallback. - Because HTML renders in real Chromium 130+, modern
@pageCSS rules work out of the box:
@page { size: A4; margin: 18mm; } thead { display: table-header-group; } tr { break-inside: avoid; page-break-inside: avoid; } - Uses Cloudflare's REST
-
Native Word
.docxTemplate Merge → PDF (1.60send-to-end):- Legal and finance teams hate rebuilding Word contracts in HTML.
- DocEngine accepts any standard
.docxfile containing{customer_name}, conditionals{#has_discount}...{/has_discount}, and repeating table rows{#items}{name} | {amount}{/items}, merges the XML in memory, and converts to PDF via an isolated Gotenberg (LibreOffice) cluster behind a Cloudflare Zero Trust Tunnel (zero exposed host ports).
-
Async Queue + Signed Webhooks for 50+ Page Reports:
- Large jobs enqueue onto Cloudflare Queues with state coordinated by a SQLite Durable Object and return immediately (
202 Accepted). - When rendering finishes, DocEngine uploads the PDF to Cloudflare R2 (with a mandatory 24-hour auto-expiry lifecycle rule) and fires an HMAC-SHA256 signed webhook (
X-DocEngine-Signature) with an expiring signed download URL.
- Large jobs enqueue onto Cloudflare Queues with state coordinated by a SQLite Durable Object and return immediately (
Hardening Against SSRF in Arbitrary HTML Templates
Rendering user-supplied HTML in headless Chromium is a classic SSRF vector (<img src="http://169.254.169.254/latest/meta-data">). Every render passes through a strict Go RE2 rejectRequestPattern firewall before any subrequest leaves Chromium:
rejectRequestPattern: [ "^https?://(localhost|127\\.|10\\.|169\\.254\\.|192\\.168\\.|172\\.(1[6-9]|2[0-9]|3[01])\\.|0\\.|\\[?(::1|fc|fd|fe[89ab]))" ] Combine that with JavaScript disabled by default, SHA-256 hashed API keys (sk_live_*) verified in constant time, and 24-hour R2 auto-deletion, and sensitive invoices or medical/HR documents never linger on disk.
Try It Live (No Signup Required)
- Interactive Browser PDF Sandbox & 40s Demo: https://docengine.cubbingsolutions.com
- Developer Docs, Bubble Recipes & OpenAPI 3.1 Spec: https://docengine-docs.cubbingsolutions.com
- MIT Open-Source Bubble.io Plugin (
DocEngine Free): https://bubble.io/plugin/docengine-free-1795683751182x808255331712368600
We made the client-side plugin + 50 server renders/month completely free forever (with a $5/mo Pro or $49 one-time Lifetime tier if you scale to production).
Would love to hear how you handle PDF generation or .docx templating in your stack — drop your toughest layout edge case in the comments!

