FrameForge › Guides › HTML to PDF in Python

HTML to PDF in Python

Send HTML (or a URL) to the FrameForge API and get a PDF back. It is rendered in real Chromium, so modern CSS, web fonts and JavaScript all work. No browser to install or babysit.

The code

Python 3 with requests. Set FRAMEFORGE_KEY to your API key.

import os
import requests

resp = requests.post(
    "https://api.frameforgeapi.com/render",
    headers={"X-API-Key": os.environ["FRAMEFORGE_KEY"]},
    json={
        "html": "<h1>Invoice #1001</h1><p>Total: £49.00</p>",
        "format": "pdf",
        "width": 794,   # A4 at 96 DPI
        "height": 1123,
    },
    timeout=60,
)
resp.raise_for_status()
with open("invoice.pdf", "wb") as f:
    f.write(resp.content)

How it works

Rendering a URL instead of HTML

{"url": "https://example.com/report", "format": "pdf", "width": 1280, "height": 800, "fullPage": true}

Doing it yourself instead

Playwright for Python gives you the same Chromium engine locally. WeasyPrint is a solid pure-Python option for print-style documents, but it does not run JavaScript.

An API makes sense when you don't want Chromium on your servers, or when you need images (PNG/JPEG) and PDFs from the same call. If you render a few PDFs a month on a server you already run, self-hosting is perfectly reasonable.

Free tool: Website to PDF. Other languages: Node.js · PHP · Ruby · Go · Java · C# / .NET · curl / Bash · Next.js · Laravel · Django · Ruby on Rails