Guides · Python · requests

Verify a fillable PDF render without opening the file in Python with requests

When form-PDF generation is part of a pipeline — nightly exports, CI checks, a queue worker — "did it actually come out fillable?" needs a machine answer, not a human opening Acrobat. snapdok puts the verification data in the response headers, so your code can assert on the render it just received.

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("checked.pdf", "wb") as f:
    f.write(resp.content)
print(resp.headers.get("X-Form-Fields"), "# assert on this in CI")

Three headers carry the contract. X-Form-Fields is the number of AcroForm fields placed — assert it equals the number of controls your form has, and you have a regression test that catches a broken deploy of your own form page, too. X-Form-Skipped counts controls that could not convert (file pickers, hidden inputs, iframe forms); a sudden rise means someone changed the form. X-Form-Extracted tells you whether pdf_form_only actually pruned the page or fell back to the full page — fallback is legitimate output, but your layout expectations may differ.

Two operational notes for pipelines: failed renders are never metered, and a repeat of an identical request inside 24 hours returns X-Cache: HIT and is also not charged — so a retrying job that occasionally double-fires does not eat quota. Rate limits surface as HTTP 429 with a Retry-After header; honour it instead of hammering.

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-FieldsFields placed — the number to assert on.
X-Form-SkippedUnconvertible controls; watch for regressions.
X-Form-ExtractedPrune result when pdf_form_only was requested.
Retry-AfterPresent on 429 — seconds to back off.

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