Guides · Python · requests

Get a fillable PDF of just the form — no nav, no footer in Python with requests

A fillable PDF of a whole web page still carries the web page around it: the navigation bar, the cookie banner, the footer with forty links. Adding "pdf_form_only": true to a pdf_forms render prunes the document down to just the form — fields with their labels, the group headings, and the title directly above it. What comes out looks like the paper version of the form, not a printout of the website.

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,
        "pdf_form_only": True,
    },
    timeout=90,
)
resp.raise_for_status()

with open("form-only.pdf", "wb") as f:
    f.write(resp.content)
print(resp.headers.get("X-Form-Extracted"), "# true = pruned to the form; false = full page")

This flag is best-effort by design, and you should code for that. When the extractor cannot identify a form region it is sure about — no visible controls, a lone search box, a form wrapping the entire page (common on older ASP.NET sites), iframes, JavaScript widget "forms" — it falls back to the full page: the exact bytes pdf_forms alone would have produced, never a half-broken cut. The rule it is built around: better a navigation bar too many than a required field too few.

The response tells you which way it went: X-Form-Extracted: true means the PDF is the pruned form, false means the full page, with the machine reason in X-Form-Extract-Fallback. The flag is ignored unless format is "pdf" and pdf_forms is true, and it is metered as one ordinary render — no extra charge.

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-Extractedtrue when the prune happened, false on fallback.
X-Form-Extract-FallbackWhy extraction fell back, when it did.
X-Form-FieldsFields placed either way.

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