PricingDocumentationCase StudiesBlogLoginGet started →

Guides

HTML to PDF in Python

Generate PDFs from HTML templates in Python with a simple HTTP request. No headless browsers required.

The problem with Python PDF libraries

Libraries like WeasyPrint and ReportLab require complex setup and limited CSS support. Puppeteer via Pyppeteer adds a heavy Chromium dependency. For production applications, a managed HTML to PDF API is simpler, faster, and more reliable.

Rendering a PDF with requests

render.py
import requests

response = requests.post(
    "https://api.pdfapi.dev/v1/render",
    headers={
        "Authorization": "Bearer YOUR_API_KEY",
        "Content-Type": "application/json",
    },
    json={
        "html": "<h1>Hello {{name}}</h1>",
        "data": {"name": "World"},
    },
)

result = response.json()
print("PDF URL:", result["url"])

Working with templates

Save your HTML designs as reusable templates in the PDF API dashboard, then render them by referencing the template ID. This is ideal for Django or Flask apps generating invoices, shipping labels, or certificates with dynamic data.

Next steps