PDF generation from code is still painful in 2026. You either wrestle with complex libraries that need 200+ lines for a simple invoice, or pay for bloated enterprise services.
So I built PDFGen AI — a simple REST API where you send HTML and get a PDF URL back. Or better — describe what you want in plain English and AI generates the template for you.
The Problem
Every developer who's tried to generate PDFs programmatically knows the pain:
- wkhtmltopdf — outdated, rendering issues, painful to install on servers
- Puppeteer/Playwright — powerful but heavy, needs headless Chrome
- jsPDF — client-side only, limited styling
- PDFKit — low-level, you're drawing rectangles manually
- Paid services — $50-200/month for what should be a simple API call
All I wanted was: send HTML, get a PDF. That's it.
The Solution: One API Call
curl -X POST https://pdfgen-api.vercel.app/api/generate \
-H "Authorization: Bearer pk_your_key" \
-H "Content-Type: application/json" \
-d '{"html": "<h1>Invoice #001</h1><p>Amount: $500</p>"}'
Response:
{
"success": true,
"url": "https://storage.supabase.co/pdfs/invoice-abc123.pdf"
}
That's the entire integration. No SDKs. No config files. No dependencies.
The AI Magic
Instead of writing HTML yourself, you can use AI to do the heavy lifting.
Generate a Template from a Description
curl -X POST https://pdfgen-api.vercel.app/api/ai/template \
-H "Authorization: Bearer pk_your_key" \
-H "Content-Type: application/json" \
-d '{"prompt": "Professional invoice with logo, line items, tax, payment terms"}'
AI generates a complete, styled HTML template you can reuse.
Fill a Template with Data Automatically
curl -X POST https://pdfgen-api.vercel.app/api/ai/fill \
-H "Authorization: Bearer pk_your_key" \
-H "Content-Type: application/json" \
-d '{
"template": "<your-html-template>",
"data": {
"company": "Acme Corp",
"items": [
{"name": "Web Development", "amount": 50000},
{"name": "Hosting", "amount": 12000}
],
"tax_rate": 0.18
}
}'
AI maps your JSON data to the template fields — no manual field mapping needed.
JavaScript Example
const response = await fetch(
"https://pdfgen-api.vercel.app/api/generate",
{
method: "POST",
headers: {
Authorization: "Bearer pk_your_key",
"Content-Type": "application/json",
},
body: JSON.stringify({
html: '<h1>Invoice #001</h1><p>Total: $1,500</p>',
}),
}
);
const { url } = await response.json();
console.log("PDF ready:", url);
Python Example
import requests
response = requests.post(
"https://pdfgen-api.vercel.app/api/generate",
headers={
"Authorization": "Bearer pk_your_key",
"Content-Type": "application/json",
},
json={
"html": "<h1>Receipt</h1><p>Amount: $250</p><p>Status: Paid</p>"
},
)
print("PDF ready:", response.json()["url"])
The Stack
Here's what powers PDFGen AI:
| Layer | Technology | Why |
|---|---|---|
| Hosting | Vercel (serverless) | Zero config, auto-scaling |
| Framework | Next.js (App Router) | API routes + frontend in one |
| Auth + DB | Supabase | PostgreSQL, auth, file storage |
| PDF Rendering | Puppeteer + @sparticuz/chromium | HTML to PDF in serverless |
| AI | AWS Bedrock (Nova Micro) | Fast, cheap template generation |
| Billing | Lemon Squeezy | Merchant of Record |
The Chromium Challenge
The hardest part was getting Puppeteer to work on Vercel serverless. The standard Chromium binary is too large. Here's what worked:
- Use
@sparticuz/chromium— stripped-down build for serverless - Add
outputFileTracingIncludesin next.config.ts to bundle the binary - Launch with
headless: "shell"mode for faster startup - Disable GPU with
setGraphicsMode = false
Cold-start PDF generation: under 5 seconds.
Why Supabase?
- Auth — email/password with magic links, zero config
- Database — PostgreSQL for API keys, usage tracking
- Storage — PDFs stored with signed URLs
- Free tier — generous enough for an MVP
Why AWS Bedrock?
I originally used the Anthropic API directly, but switched to Bedrock:
- Pay-per-use — no monthly minimums
- Amazon Nova Micro — fast, cheap, perfect for templates
- Bearer token auth — simple, no complex AWS SDK needed
5 Built-in Templates
PDFGen AI comes with ready-to-use templates:
- Invoice — line items, tax, totals
- Receipt — clean payment receipt
- Report — business report with sections
- Certificate — achievement/completion
- Letter — formal business letter
Lessons Learned Building Solo
Start with the API, not the UI. I tested with curl for weeks before building the frontend. Forced me to get the DX right.
Free tiers are your friend. Total infra cost: ~$0/month. Vercel free, Supabase free, Bedrock pay-per-call.
Billing in India is tricky. Stripe doesn't support Indian merchants for international payments. Lemon Squeezy acts as Merchant of Record — handles global payments, pays you out.
SEO from day one. Sitemap, robots.txt, JSON-LD, OG images — all added before launch. 10x easier than retrofitting.
Ship fast. Idea to production in 4 weeks. Not perfect, but working.
Pricing
| Plan | Price | PDFs/month | AI calls/month |
|---|---|---|---|
| Free | $0 | 50 | 10 |
| Starter | $19/mo | 2,000 | 100 |
| Pro | $49/mo | 15,000 | 500 |
| Business | $99/mo | 100,000 | 2,000 |
| Enterprise | $299/mo | Unlimited | 5,000 |
No credit card required for free tier.
What's Next
- More built-in templates based on user requests
- Webhook notifications when PDF is ready
- Batch generation — hundreds of PDFs in one call
- Custom font uploads
- PDF merging
Try It
The API is live and free to start:
Website: pdfgen-api.vercel.app
Docs: pdfgen-api.vercel.app/docs
Sign up, grab your API key, and generate your first PDF in under a minute.
I'd love feedback — especially on the API design and developer experience. What would you build with it?
Built solo with Next.js, Supabase, AWS Bedrock, and too much coffee.
Top comments (0)