Guides · PHP · cURL extension
Verify a fillable PDF render without opening the file in PHP with cURL extension
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 PHP program using cURL extension, no third-party dependency needed. It reads your API key from the SNAPDOK_KEY environment variable — free keys take about thirty seconds and need no card.
<?php
$body = json_encode([
'url' => "https://your-app.com/intake-form",
'format' => "pdf",
'pdf_forms' => true,
'pdf_form_only' => true,
]);
$ch = curl_init("https://snapdok.io/v1/render");
$headers = [];
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $body,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 90,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('SNAPDOK_KEY'),
'Content-Type: application/json',
],
CURLOPT_HEADERFUNCTION => function ($ch, $line) use (&$headers) {
$parts = explode(':', $line, 2);
if (count($parts) === 2) $headers[strtolower(trim($parts[0]))] = trim($parts[1]);
return strlen($line);
},
]);
$bytes = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
if ($status !== 200) {
throw new RuntimeException("snapdok error $status: $bytes");
}
file_put_contents('checked.pdf', $bytes);
echo ($headers['x-form-fields'] ?? '?') . " // assert on this in CI\n";
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 cURL extension
Plain ext-curl, no Composer needed. The details that bite: CURLOPT_RETURNTRANSFER must be set or the bytes are echoed to stdout instead of returned; the HTTP status has to be read explicitly with curl_getinfo() because cURL happily "succeeds" on a 401; and response headers need a CURLOPT_HEADERFUNCTION callback if you want to check things like X-Form-Fields. file_put_contents is binary-safe in PHP — strings are byte arrays — so no "b" flag dance is needed.
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 Python with requests
- 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 Ruby with Net::HTTP
More with PHP + cURL extension
- 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