DEV Community

Ing. Pablo Cueto
Ing. Pablo Cueto

Posted on

How I built a PDF Generator API with FastAPI and ReportLab

The problem

Almost every SaaS app needs to generate PDFs at some point — invoices,
reports, receipts. Most developers end up wrestling with Puppeteer,
wkhtmltopdf, or heavy libraries that are painful to deploy.

I decided to build a simple REST API that does it with a single POST request.

The stack

  • FastAPI — for the REST endpoints
  • ReportLab — for PDF generation in Python
  • Docker + Render — for deployment
  • RapidAPI — for monetization

How it works

Send a JSON payload, get a PDF back:

import requests

response = requests.post(
    "https://pdf-generator-api-1fx5.onrender.com/generate/invoice",
    headers={"X-API-Key": "your-key"},
    json={
        "invoice_number": "INV-2025-001",
        "company": {"name": "Acme Corp", "email": "billing@acme.com"},
        "client": {"name": "John Doe", "email": "john@example.com"},
        "items": [
            {"description": "Web Development", "quantity": 10, "unit_price": 150}
        ],
        "tax_rate": 16
    }
)

with open("invoice.pdf", "wb") as f:
    f.write(response.content)
Enter fullscreen mode Exit fullscreen mode

What it generates

  • Invoice PDFs — with line items, tax calculation and totals
  • HTML to PDF — convert any HTML string to PDF
  • Report PDFs — turn tabular data into formatted reports

Try it free

Available on RapidAPI with a free tier (50 requests/month):
🔗 https://rapidapi.com/PabsCueto/api/pdf-generator17

Would love feedback from the community!

Top comments (0)