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
| Header | Meaning |
|---|---|
X-Form-Fields | Fields placed — the number to assert on. |
X-Form-Skipped | Unconvertible controls; watch for regressions. |
X-Form-Extracted | Prune result when pdf_form_only was requested. |
Retry-After | Present on 429 — seconds to back off. |
Full parameter reference: the docs. Hard numbers on caps and timeouts: limits.
Related guides
Same task, other stacks
- Verify a fillable PDF render without opening the file in Node.js with built-in fetch
- Verify a fillable PDF render without opening the file in PHP with cURL extension
- Verify a fillable PDF render without opening the file in Ruby with Net::HTTP
More with Python + requests
- Convert an HTML form to a fillable PDF
- Get a fillable PDF of just the form — no nav, no footer
- Generate a fillable invoice PDF from a web page
- Turn an online registration form into a fillable PDF
- Wait for a JavaScript-rendered form, then make it fillable
- Convert a URL to PDF
- Take a full-page screenshot
- Capture very tall pages as numbered tiles
- Take a retina-quality (2x) screenshot
- Take a JPEG screenshot at a custom viewport size
- Use the 24-hour render cache to cut costs
- Take a screenshot of a URL
- Capture a JavaScript-heavy page after it settles
- Wait for a specific element before capturing
- Add page numbers and headers to a PDF