Fetching latest headlines…
Generate Invoice PDFs from HTML in 10 Lines of Code
NORTH AMERICA
πŸ‡ΊπŸ‡Έ United Statesβ€’June 21, 2026

Generate Invoice PDFs from HTML in 10 Lines of Code

0 views0 likes0 comments
Originally published byDev.to

I got tired of running headless Chrome myself just to turn HTML invoices into PDF attachments. So I built a small API and listed it on RapidAPI: Simple PDF API.

Free tier included. No browser setup on your side.

The problem

Every SaaS eventually needs PDFs:

  • Invoices and receipts
  • Reports and exports
  • Downloadable confirmations

The usual options:

  1. Run Puppeteer/Playwright yourself β€” works, but ops pain (memory, crashes, scaling)
  2. Enterprise PDF APIs β€” great, but $15–75/mo before you have revenue
  3. wkhtmltopdf β€” dated CSS support

I wanted: JSON in β†’ PDF bytes out. One POST. Done.

The solution

curl --request POST \
  --url "https://simple-pdf-api.p.rapidapi.com/v1/html-to-pdf" \
  --header "Content-Type: application/json" \
  --header "X-RapidAPI-Key: YOUR_KEY" \
  --header "X-RapidAPI-Host: simple-pdf-api.p.rapidapi.com" \
  --data '{
    "html": "<html><body><h1>Invoice #1042</h1><p>Total: $99.00</p></body></html>",
    "page_size": "A4"
  }' \
  --output invoice.pdf

That's it. You get raw application/pdf bytes back.

JavaScript example

const res = await fetch("https://simple-pdf-api.p.rapidapi.com/v1/html-to-pdf", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-RapidAPI-Key": process.env.RAPIDAPI_KEY,
    "X-RapidAPI-Host": "simple-pdf-api.p.rapidapi.com",
  },
  body: JSON.stringify({
    html: invoiceHtml,
    page_size: "A4",
  }),
});

const pdf = Buffer.from(await res.arrayBuffer());
// attach to email, upload to S3, etc.

Python example

import requests

resp = requests.post(
    "https://simple-pdf-api.p.rapidapi.com/v1/html-to-pdf",
    headers={
        "X-RapidAPI-Key": "YOUR_KEY",
        "X-RapidAPI-Host": "simple-pdf-api.p.rapidapi.com",
    },
    json={"html": invoice_html, "page_size": "A4"},
    timeout=90,
)
resp.raise_for_status()

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

What else is included

Same API key, same subscription:

  • HTML or URL β†’ PDF β€” full CSS via headless Chromium
  • Merge PDFs β€” combine multiple documents
  • Split PDF β€” extract page ranges
  • Watermark β€” add CONFIDENTIAL / DRAFT overlays
  • Compress β€” reduce file size by removing duplicate objects
  • Protect β€” AES password-encrypt with configurable print permissions
  • Rotate β€” rotate all or selected pages by 90, 180, or 270Β°
  • Extract text β€” pull plain text for search/indexing

8 endpoints, one API key.

Pricing

Plan Price Quota
BASIC Free ~50 req/day
PRO $9/mo 5,000 req/mo
ULTRA $29/mo 25,000 req/mo

Enough free tier to test. PRO is priced for indie devs and early-stage SaaS.

Try it

  1. Subscribe on RapidAPI (free plan)
  2. Copy your API key
  3. Paste the curl above
  4. Open invoice.pdf

Interactive API docs: https://pdf-api-production-9570.up.railway.app/docs

Built with FastAPI + Playwright. Happy to answer integration questions in the comments.

Comments (0)

Sign in to join the discussion

Be the first to comment!