Prompt
I'm building an invoicing app and need an API for PDF generation
Latest observation
Absolutely — for an invoicing app, a PDF generation API should ideally be simple, reliable, and designed for document workflows like invoices, quotes, receipts, and statements.
What the API should support
At minimum:
- Generate PDFs from data: invoice JSON → PDF
- Template support: reusable invoice layouts
- Customization: logo, branding, colors, tax labels, currency, page size
- Line-item tables: products/services, quantities, discounts, totals
- Attachments: optionally include terms, receipt, or supporting docs
- Delivery options:
- return PDF bytes/base64
- return a signed download URL
- email the PDF to a customer
- Metadata: invoice number, customer info, issue/due dates, status
- Multi-page handling: long line-item lists
- Internationalization: currency formatting, date formats, locale
- Security: authenticated access, access tokens, expiring links
Recommended API design
1) Create a PDF from invoice data
POST /v1/pdfs/invoices
{
"template_id": "tpl_standard_invoice",
"invoice": {
"invoice_number": "INV-10023",
"issue_date": "2026-10-12",
"due_date": "2026-11-12",
"currency": "USD",
"customer": {
"name": "Acme Corp",
"email": "billing@acme.com",
"address": "123 Market St, San Francisco, CA"
},
"company": {
"name": "My SaaS Inc",
"address": "42 Main St, New York, NY",
"tax_id": "US-123456789"
},
"items": [
{
"description": "Pro plan subscription",
"quantity": 1,
"unit_price": 99.0,
"tax_rate": 0.07
}
],
"notes": "Thank you for your business"
}
}
Response
{
"pdf_id": "pdf_abc123",
"status": "ready",
"download_url": "https://cdn.example.com/pdfs/pdf_abc123.pdf",
"expires_at": "2026-10-12T18:00:00Z"
}
2) Generate and return the PDF directly
POST /v1/pdfs/render
Use this if you want the API to return the file stream directly.
Headers:
Accept: application/pdf
Response:
200 OKContent-Type: application/pdf
3) Template management
GET /v1/templates
POST /v1/templates
GET /v1/templates/{template_id}
PUT /v1/templates/{template_id}
Template data could include:
{
"name": "Standard Invoice",
"size": "A4",
"orientation": "portrait",
"colors": {
"primary": "#1E40AF",
"text": "#111827"
},
"logo_url": "https://example.com/logo.png",
"footer_text": "Payment due within 30 days"
}
Useful features for invoicing specifically
Line item calculations
The API should calculate:
- subtotal
- tax
- discounts
- shipping
- grand total
- amount paid / outstanding balance
Rendering options
Support:
- HTML/CSS templates
- Markdown to PDF
- programmatic layout JSON
- image embedding for logos/signatures
Webhook support
For async generation:
pdf.generatedpdf.failed
This is useful when PDFs are created in background jobs.
Example async workflow
- Client sends invoice JSON
- API returns job ID
- Worker generates PDF
- Webhook notifies app when ready
Suggested minimal OpenAPI endpoints
POST /v1/pdfs/invoicesGET /v1/pdfs/{pdf_id}GET /v1/pdfs/{pdf_id}/downloadPOST /v1/templatesGET /v1/templatesPUT /v1/templates/{template_id}
Implementation options
Depending on your stack:
- Node.js: Puppeteer, Playwright, pdf-lib, PDFKit
- Python: WeasyPrint, ReportLab, CairoSVG
- Java: OpenPDF, iText
- Go: UniDoc, wkhtmltopdf wrapper
- Headless browser rendering: best for pixel-perfect invoice templates
For invoicing, HTML/CSS + headless Chromium is often the easiest way to get good-looking results.
If you want a production-ready API
I can help you with any of these next steps:
- Design a full OpenAPI spec
- Create a Node.js/Express PDF generation service
- Build a FastAPI service
- Design invoice JSON schema
- Add webhook + async job queue support
- Create an HTML invoice template
If you want, I can generate a complete OpenAPI 3.0 spec for this PDF API now.