AI News Hub Logo

AI News Hub

Generate Beautiful PDF Invoices from JSON in 3 Lines of Code

DEV Community
Jack

Need to generate invoices programmatically? Here's how to go from JSON to a professional PDF in seconds, no libraries to install. Every SaaS, freelancer platform, and e-commerce app needs invoices. The usual approach: Install a PDF library (ReportLab, WeasyPrint, Puppeteer) Design a template Handle fonts, margins, page breaks, currency formatting Debug why it looks different on every OS Maintain it forever Or... just send JSON and get a PDF back. import requests response = requests.post('https://documint.anethoth.com/api/v1/demo-invoice', json={ 'company': 'Acme Corp', 'client': 'Jane Smith', 'items': [ {'description': 'Web Development', 'quantity': 40, 'unit_price': 125}, {'description': 'Design Review', 'quantity': 5, 'unit_price': 200}, {'description': 'Hosting Setup', 'quantity': 1, 'unit_price': 500} ] }) with open('invoice.pdf', 'wb') as f: f.write(response.content) That's it. Professional PDF invoice, ready to send. The API supports three templates — pass "template": "modern" or "template": "minimal" in the JSON body. Traditional business layout with clean lines and professional typography. Gradient accents, rounded cards, contemporary feel. Great for tech companies and agencies. Monospace font, ultra-clean design. Popular with freelancers and consultants. const response = await fetch('https://documint.anethoth.com/api/v1/demo-invoice', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ company: 'Acme Corp', items: [{ description: 'API Integration', quantity: 1, unit_price: 2500 }] }) }); const buffer = await response.arrayBuffer(); require('fs').writeFileSync('invoice.pdf', Buffer.from(buffer)); curl -X POST https://documint.anethoth.com/api/v1/demo-invoice \ -H 'Content-Type: application/json' \ -d '{"company": "Acme Corp", "items": [{"description": "Consulting", "quantity": 10, "unit_price": 150}]}' \ --output invoice.pdf open invoice.pdf # macOS xdg-open invoice.pdf # Linux package main import ( "bytes" "encoding/json" "io" "net/http" "os" ) func main() { invoice := map[string]interface{}{ "company": "Acme Corp", "items": []map[string]interface{}{ {"description": "Backend Development", "quantity": 80, "unit_price": 100}, }, } body, _ := json.Marshal(invoice) resp, _ := http.Post( "https://documint.anethoth.com/api/v1/demo-invoice", "application/json", bytes.NewReader(body), ) defer resp.Body.Close() f, _ := os.Create("invoice.pdf") io.Copy(f, resp.Body) } The demo endpoint is free (no API key needed, rate limited to 10/minute). For production use, sign up for an API key. Full JSON schema: { "company": "Your Company Name", "company_address": "123 Main St, City, State 12345", "company_email": "[email protected]", "company_phone": "+1 (555) 123-4567", "client": "Client Name", "client_address": "456 Oak Ave, Town, State 67890", "client_email": "[email protected]", "invoice_number": "INV-2026-001", "date": "2026-04-21", "due_date": "2026-05-21", "currency": "USD", "tax_rate": 0.1, "notes": "Payment due within 30 days", "template": "modern", "items": [ { "description": "Service description", "quantity": 10, "unit_price": 100 } ] } Need to convert arbitrary HTML to PDF? There's a free endpoint for that too: curl -X POST https://documint.anethoth.com/api/v1/html-to-pdf \ -H 'Content-Type: application/json' \ -d '{"html": "Hello WorldThis becomes a PDF."}' \ --output output.pdf Supports full CSS, custom page sizes (A4, Letter, Legal), and returns production-quality PDFs. What's your current invoice generation setup? I'm curious how teams handle this — some of the solutions I've seen in the wild are... creative.