When we set out to build html2pdf—a developer API and TypeScript SDK for converting HTML and CSS into pixel-perfect PDFs—we started by conducting deep technical research across the existing landscape: legacy binaries like wkhtmltopdf, headless browser wrappers, and cloud conversion services.
We wanted to understand why generating documents from web technologies is still notoriously frustrating.
Across our research, we found the same architectural gaps and developer pain points repeating themselves:
- Friction-heavy onboarding: Requiring full registration, email confirmation, and credit cards just to test if a CSS flexbox or grid layout renders properly.
- Mangled print formatting: Engines stripping background colors by default, failing to respect print margins, or lacking native dynamic page numbering.
- Poor file ergonomics: APIs forcing end-users to download files named
9b1deb4d-3b7d-4b3f.pdfinstead of human-readable filenames. - Unnecessary storage roundtrips: Requiring an asynchronous upload to S3 and polling presigned URLs when microservices simply need raw PDF bytes to stream immediately to a client.
- Quota race conditions: Concurrent rendering requests bypassing monthly tier ceilings due to slow database checks during browser compilation.
Over the past few weeks, we systematically addressed each of these findings. Here is a breakdown of the technical research, the features we implemented, and our roadmap as we prepare to wrap up beta access and launch our payment integration.
1. Research Finding: The Testing Friction Trap
The Problem
When evaluating a PDF generation API, developers need to verify one fundamental thing: Does my HTML and CSS render accurately in their engine?
On most platforms, finding this answer requires navigating a multi-step barrier: creating an account, confirming an email, logging in, generating an API key, configuring headers in Postman or cURL, and only then discovering whether the engine supports their font or layout.
The Solution: Zero-Signup Live Sandbox (/sandbox)
We built an interactive, zero-signup browser environment at /sandbox:
Visit /sandbox ──► Pick Preset ──► Edit CSS/Margins ──► Real Chromium Compilation Proof - 5 Production Presets: Tested templates for Invoices & Tax Calculations, Executive Dashboards, Event Tickets, Certificates of Award, and 21 Indic Scripts.
- Live Engine Binding: Real-time controls for paper formats (A0–A6, Letter, Legal), orientation, CSS zoom scale (0.1–2.0), page ranges, and independent 4-way margins.
- Interactive Driver.js Tour: A 6-step developer spotlight walkthrough explaining engine controls, code exports, and compilation options.
- Instant Multi-Language Code Export: Generates ready-to-use snippets for our official TypeScript SDK, Node.js
fetch, or raw cURL with your exact parameters.
Under the hood, we use Supabase Anonymous Auth paired with Cloudflare Turnstile bot protection. The developer gets an isolated, ephemeral session with 5 full-fidelity conversions without entering an email or password.
2. Research Finding: The Guest-to-User State Gap
The Problem
In many sandbox tools, once a guest decides to register, their session state is wiped. Any custom HTML, CSS, or margins they adjusted in the playground are lost, forcing them to reconfigure their templates.
The Solution: Lossless Upgrade to Dedicated Studio (/studio)
We architected a clean state transition between anonymous testing and registered use:
/sandbox (5 trial conversions) ──► Sign Up / Google OAuth ──► /studio (1000000 free monthly conversions) - In-Place Identity Conversion: When a guest upgrades, we call
supabase.auth.updateUser({ email, password }). Supabase converts the existing anonymous user into a permanent registered user, preserving their underlyinguser.id. - Dedicated Studio Environment: Authenticated developers are automatically directed to
/studio. The studio removes all Turnstile captchas, trial countdown badges, and upgrade modals. - Auto-Provisioned Live Keys: Studio automatically provisions a non-trial live API key (
h2p_live_*) in the background. - Deep-Linked History: The preview pane includes an instant "View in History" action that links directly to the job log row in
/dashboard?view=history. - 3-Layer State Guard: A combination of SSR middleware, a 0.1ms pre-hydration inline
<script>inspectinglocalStorage, and React hydration guards guarantees that logged-in developers navigating to/sandboxare instantly redirected to/studiowith zero visual flash.
3. Research Finding: File Ergonomics & Delivery Latency
A. Custom Human-Readable Filenames (filename)
- The Gap: Most conversion APIs return documents named after internal database primary keys or UUIDs (
e4a2-41b9-8bc3.pdf). Developers had to write custom proxy layers just to rename files for their users. - Our Implementation: We added
filename: stringto our request schema. You passfilename: "Invoice-2026-001", and our API:- Sanitizes the string to eliminate invalid filesystem and URI characters.
- Emits clean
Content-Disposition: attachment; filename="Invoice-2026-001.pdf"download headers. - Stores the file in S3 as
${sanitizedName}-${jobId}.pdf, disambiguating identical filenames while keeping the public display name pristine.
B. Direct Binary Buffer Streaming (sendBuffer: true)
- The Gap: For microservices and serverless functions (Next.js API routes, Express, Fastify), uploading a generated PDF to cloud storage, generating a presigned URL, and returning JSON requires an extra network roundtrip:
API Server ──(upload)──► S3 Bucket ──(presign)──► Client ──(download)──► S3 Bucket - Our Implementation: Adding
sendBuffer: trueinstructs Fastify to return the raw binary PDF buffer (application/pdf) directly in the HTTP response body:
import { Html2PdfClient } from '@akcraft/html2pdf-sdk'; const client = new Html2PdfClient({ apiKey: process.env.HTML2PDF_API_KEY }); // Streams raw ArrayBuffer directly — zero storage roundtrip const pdfBuffer = await client.sendHtmlBuffer({ content: '<h1>Executive Summary</h1>', sendBuffer: true, filename: 'Report-Q4' }); res.setHeader('Content-Type', 'application/pdf'); res.send(Buffer.from(pdfBuffer)); Job logs and monthly quota counters are still recorded in PostgreSQL, ensuring complete accounting integrity without forcing unnecessary S3 roundtrips on the client.
4. Research Finding: Print Stripping & CSS Page Break Failures
The Gap
Standard browser print implementations often strip CSS background colors (background-color), background images, and custom gradients to save ink on physical printers. When generating digital PDFs (like invoices with dark table headers or colored status badges), this behavior completely ruins the document layout.
Extended Print Options Implemented
We exposed fine-grained print configuration across both the Fastify schema and TypeScript SDK:
-
printBackground: true(default): Explicitly preserves all CSS background fills, box shadows, and gradient styling. - Independent 4-Way Margins: Configurable
{ top, bottom, left, right }objects with units (px,mm,in). -
scale(0.1 to 2.0): Zoom factor allowing rich dashboards to fit cleanly onto standard pages. -
pageRanges: Selective page rendering (e.g.,"1-3, 5"). - Chromium Dynamic Header & Footer Templates: Native support for header and footer markup with Chromium’s built-in formatting placeholders:
<span class="pageNumber"></span> / <span class="totalPages"></span> 5. Research Finding: Concurrency Overruns in Billing Quotas
The Problem
In standard web services, a request takes 5–20ms. In a PDF generation service, headless Chromium rendering takes 500ms to 1200ms.
If a user with 1 remaining trial credit sends 10 concurrent conversion requests at the exact same millisecond:
- All 10 requests query the database simultaneously.
- All 10 find
usedCount (4) < maxLimit (5)is true. - All 10 render simultaneously in Chromium.
- The user completes 14 total conversions on a 5-conversion limit.
Our Implementation: Atomic Two-Phase Redis Reservations
We replaced database pre-checks with an atomic Redis Lua script (reserveTrialConversion):
- Pre-Allocation: Before Chromium launches, Redis atomically increments and validates the slot reservation (
EVAL). Requests exceeding the limit are rejected immediately with HTTP 429 without launching Chromium. - Safe Rollback: If Chromium crashes, the HTML fails to load, or the network disconnects,
rollbackTrialReservationautomatically refunds the reserved slot so developers are never docked for failed renders. - Soft-Revoke Architecture: When an API key is revoked, the system stamps
revoked_atinstead of executing a databaseCASCADE DELETE, preserving historical job logs and preventing billing quota resets.
6. What We Are Working On Now: Credit-Based Conversions & Pro Tier
We are in the final stretch of our beta phase. Over the coming weeks, we will transition from beta to our complete production release.
The Upcoming Pricing & Entitlement Model:
- Credit-Based Conversion Engine:
- Shifting to a clean conversion credit model where successful renders consume credits. Failed renders do not consume credits.
- Free Tier: 500 free conversion credits for developer testing and small projects.
- Pro Tier (Unlocking High-Throughput Batching):
- Removal of the Per-Minute Rate Limit: Free accounts are constrained by a per-minute rate limit (e.g. 10 req/min) to prevent burst abuse. Pro accounts completely remove the per-minute limit, allowing high-throughput batch conversions and parallel microservice document generation.
- Publishing our updated TypeScript client with TypeBox schemas, custom filename helpers, and automatic
retry-afterhandling on npm.
Explore the Engine
You can test our rendering pipeline right now without creating an account:
- Live Sandbox: Compile sample invoices, tickets, and Indic documents in your browser.
- Developer Studio: For registered developers building production templates.
- SDK on NPM: Type-safe TypeScript client for Node.js.
Have questions about our Chromium setup or fontconfig pipeline? Drop a comment below—we're happy to discuss the technical details.
