Automated PDF Invoice Generation: Build It in 10 Minutes

April 11, 2026

Every SaaS needs invoices. The question is: do you spend a week integrating wkhtmltopdf, fighting Puppeteer in Docker, or wrestling with LaTeX templates? Or do you send one API call and get a PDF back?

The HTML template approach

The fastest way to generate invoices is to design them in HTML/CSS — tools you already know — then render to PDF via API. Here's a complete example.

Step 1: Build your invoice template

<div style="max-width:700px;margin:0 auto;padding:40px;font-family:sans-serif">
  <div style="display:flex;justify-content:space-between;margin-bottom:40px">
    <div>
      <h1 style="margin:0;font-size:24px">INVOICE</h1>
      <p style="color:#666;margin:4px 0">#INV-2026-042</p>
      <p style="color:#666;margin:4px 0">April 11, 2026</p>
    </div>
    <div style="text-align:right">
      <h2 style="margin:0;font-size:18px">Your Company</h2>
      <p style="color:#666;margin:4px 0">[email protected]</p>
    </div>
  </div>

  <table style="width:100%;border-collapse:collapse;margin-bottom:30px">
    <thead>
      <tr style="border-bottom:2px solid #333">
        <th style="text-align:left;padding:8px 0">Item</th>
        <th style="text-align:right;padding:8px 0">Amount</th>
      </tr>
    </thead>
    <tbody>
      <tr style="border-bottom:1px solid #eee">
        <td style="padding:8px 0">Growth Plan — April 2026</td>
        <td style="text-align:right;padding:8px 0">$49.00</td>
      </tr>
      <tr>
        <td style="padding:8px 0;font-weight:bold">Total</td>
        <td style="text-align:right;padding:8px 0;font-weight:bold">$49.00</td>
      </tr>
    </tbody>
  </table>

  <p style="color:#666;font-size:14px">Payment received. Thank you!</p>
</div>

Step 2: Render to PDF

import requests

invoice_html = build_invoice(customer, line_items)  # your template function

resp = requests.post(
    "https://screenshotapis.org/v1/pdf",
    headers={"X-Api-Key": "sk_live_your_key"},
    json={
        "html": invoice_html,
        "format": "A4",
        "print_background": True,
    },
)

with open(f"invoice-{invoice_id}.pdf", "wb") as f:
    f.write(resp.content)

Step 3: Email it

Attach the PDF bytes to your transactional email. Works with SendGrid, Resend, Postmark, or any email provider that accepts attachments.

Why this beats the alternatives

Tips for production invoices

Generate PDF invoices from HTML — no browser required

Get your API key — free