Guides · Python · requests

Turn an online registration form into a fillable PDF in Python with requests

Every event eventually meets a participant who cannot — or will not — register online: no account, a locked-down work laptop, a school that wants paper on file. The usual answer is maintaining a second, Word-document copy of the form that drifts out of sync with the web one. The better answer is generating the paper copy from the web form, so there is exactly one source of truth.

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/events/spring-workshop/register",
        "format": "pdf",
        "pdf_forms": True,
        "pdf_form_only": True,
    },
    timeout=90,
)
resp.raise_for_status()

with open("registration.pdf", "wb") as f:
    f.write(resp.content)
print(resp.headers.get("X-Form-Fields"), "# fields on the printed form")

Radio groups are the detail to check on registration forms: a set of <input type="radio"> sharing a name becomes a proper PDF radio group — pick one and the others clear, same as on the page. Checkbox consents ("email me about future workshops") stay independently tickable. A <select> of ticket types becomes a dropdown in the PDF reader.

With pdf_form_only the render drops your site's navigation and prints just the form block with its headings — hand that straight to a printer. And because fields keep their HTML names, a filled copy that comes back to you can be read programmatically with any PDF library and fed into the same handler your web form posts to.

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 controls made it into the PDF.
X-Form-SkippedAnything skipped — compare against your form.
X-Form-ExtractedWhether the page was pruned to the form.

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