PDFPipeDocs

Guide

Generate a PDF from HTML in Python

Python has plenty of PDF libraries, and each comes with a catch. WeasyPrint does not run modern JavaScript and trips on some CSS. ReportLab means drawing the document by hand. Running Playwright or Puppeteer gives you real Chromium, and also the job of keeping Chromium alive in production. Here is the version that skips all of that.

Why not just use WeasyPrint?

WeasyPrint is great for simple, static layouts. The moment your template uses flexbox edge cases, a charting library, or a web font that needs to load, fidelity slips. And anything that renders untrusted HTML needs SSRF protection you now have to build yourself.

One request from FastAPI

POST your HTML to a rendering API and stream the PDF back. No Chromium to install, no system libraries to pin in your Docker image.

Python
# pip install fastapi httpx
import os, httpx
from fastapi import FastAPI, HTTPException
from fastapi.responses import Response

app = FastAPI()
PDFPIPE_KEY = os.environ["PDFPIPE_API_KEY"]

@app.post("/invoice/{order_id}")
async def invoice(order_id: str):
    async with httpx.AsyncClient(timeout=60) as client:
        r = await client.post(
            "https://api.pdfpipe.xyz/v1/pdf",
            headers={"Authorization": f"Bearer {PDFPIPE_KEY}"},
            json={
                "html": f"<h1>Invoice {order_id}</h1>",
                "options": {"format": "A4"},
            },
        )
    if r.status_code != 200:
        raise HTTPException(502, r.json().get("detail", "render failed"))
    return Response(
        content=r.content,
        media_type="application/pdf",
        headers={"Content-Disposition": f'attachment; filename="invoice-{order_id}.pdf"'},
    )

Set PDFPIPE_API_KEY and you are done. The renderer waits for fonts and images, honors break-inside: avoid for long tables, and returns a clear error you can surface, not a stack trace.

Rendering from a URL

Python
json={"url": "https://example.com/report", "options": {"format": "A4"}}

PDFPipe is the API above. Flat pricing, 500 free documents a month, and a live playground with no signup.

See pricing →