DEV Community

Jack
Jack

Posted on • Originally published at anethoth.com

Generate Beautiful PDF Invoices from JSON in 3 Lines of Code

Need to generate invoices programmatically? Here's how to go from JSON to a professional PDF in seconds, no libraries to install.

The Problem

Every SaaS, freelancer platform, and e-commerce app needs invoices. The usual approach:

  1. Install a PDF library (ReportLab, WeasyPrint, Puppeteer)
  2. Design a template
  3. Handle fonts, margins, page breaks, currency formatting
  4. Debug why it looks different on every OS
  5. Maintain it forever

Or... just send JSON and get a PDF back.

The 3-Line Solution

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)
Enter fullscreen mode Exit fullscreen mode

That's it. Professional PDF invoice, ready to send.

Three Template Styles

The API supports three templates — pass "template": "modern" or "template": "minimal" in the JSON body.

Classic (default)

Traditional business layout with clean lines and professional typography.

Modern

Gradient accents, rounded cards, contemporary feel. Great for tech companies and agencies.

Minimal

Monospace font, ultra-clean design. Popular with freelancers and consultants.

Node.js Version

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));
Enter fullscreen mode Exit fullscreen mode

cURL (for quick tests)

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
Enter fullscreen mode Exit fullscreen mode

Go Version

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)
}
Enter fullscreen mode Exit fullscreen mode

Full Invoice Schema

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": "billing@company.com",
  "company_phone": "+1 (555) 123-4567",
  "client": "Client Name",
  "client_address": "456 Oak Ave, Town, State 67890",
  "client_email": "client@example.com",
  "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
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Also: Free HTML-to-PDF

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": "<h1>Hello World</h1><p>This becomes a PDF.</p>"}' \
  --output output.pdf
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (0)