Guides · Python · requests

Convert an HTML form to a fillable PDF in Python with requests

A plain URL-to-PDF render gives you a picture of a form — nice to look at, impossible to type into. Setting "pdf_forms": true (with "format": "pdf") changes what comes back: every supported control on the page becomes a real AcroForm field at its exact rendered position, and the PDF can be filled in with Adobe Acrobat, macOS Preview, a browser viewer or a phone reader, then saved with the values kept.

Below is a complete, runnable Python program using requests (pip install requests). It reads your API key from the SNAPDOK_KEY environment variable — free keys take about thirty seconds and need no card.

import os
import requests

resp = requests.post(
    "https://snapdok.io/v1/render",
    headers={"Authorization": "Bearer " + os.environ["SNAPDOK_KEY"]},
    json={
        "url": "https://your-app.com/intake-form",
        "format": "pdf",
        "pdf_forms": True,
    },
    timeout=90,
)
resp.raise_for_status()

with open("fillable.pdf", "wb") as f:
    f.write(resp.content)
print(resp.headers.get("X-Form-Fields"), "# AcroForm fields placed")

What converts: text-like <input>s (text, email, tel, date, password, number) become text fields — password renders masked and maxlength is enforced; <textarea> becomes a multiline field; checkboxes stay checkboxes; radio inputs sharing a name become a radio group with one choice across the group; <select> becomes a dropdown. Pre-filled values, readonly and checked state carry over.

What does not: file pickers, range sliders, color pickers, hidden or invisible inputs, forms inside iframes, and fake widgets built from styled divs. These are skipped cleanly and counted in X-Form-Skipped — never guessed at, never dropped in the wrong spot.

One layout consequence worth knowing before you file a bug: the forms path measures the page at paper width with print styles — the same geometry an ordinary PDF render uses — so the width parameter has no effect here, and a mobile-first page comes out in its paper layout, not its phone layout.

Notes for requests

Three requests-specific details the sample already handles. resp.content is the binary body — resp.text would decode PDF bytes as text and corrupt them. raise_for_status() turns a JSON error response into an exception instead of letting it reach the open(..., "wb") call. And requests has no default timeout — without the explicit timeout= a hung connection blocks forever, which matters for a call that drives a real browser and legitimately takes seconds.

Response headers worth reading

HeaderMeaning
X-Form-FieldsHow many AcroForm fields were placed.
X-Form-SkippedControls skipped (unsupported or invisible).
X-CacheHIT when served from the 24h cache — not charged.

Full parameter reference: the docs. Hard numbers on caps and timeouts: limits.

Related guides

Same task, other stacks

More with Python + requests

In the wild