Guides · PHP · cURL extension
Convert an HTML form to a fillable PDF in PHP with cURL extension
A plain URL-to-PDF render gives you a picture of a form — nice to look at, impossible to type into. Setting "pdf_forms": true (with "format": "pdf") changes what comes back: every supported control on the page becomes a real AcroForm field at its exact rendered position, and the PDF can be filled in with Adobe Acrobat, macOS Preview, a browser viewer or a phone reader, then saved with the values kept.
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,
]);
$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('fillable.pdf', $bytes);
echo ($headers['x-form-fields'] ?? '?') . " // AcroForm fields placed\n";
What converts: text-like <input>s (text, email, tel, date, password, number) become text fields — password renders masked and maxlength is enforced; <textarea> becomes a multiline field; checkboxes stay checkboxes; radio inputs sharing a name become a radio group with one choice across the group; <select> becomes a dropdown. Pre-filled values, readonly and checked state carry over.
What does not: file pickers, range sliders, color pickers, hidden or invisible inputs, forms inside iframes, and fake widgets built from styled divs. These are skipped cleanly and counted in X-Form-Skipped — never guessed at, never dropped in the wrong spot.
One layout consequence worth knowing before you file a bug: the forms path measures the page at paper width with print styles — the same geometry an ordinary PDF render uses — so the width parameter has no effect here, and a mobile-first page comes out in its paper layout, not its phone layout.
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 | How many AcroForm fields were placed. |
X-Form-Skipped | Controls skipped (unsupported or invisible). |
X-Cache | HIT when served from the 24h cache — not charged. |
Full parameter reference: the docs. Hard numbers on caps and timeouts: limits.
Related guides
Same task, other stacks
- Convert an HTML form to a fillable PDF in Python with requests
- Convert an HTML form to a fillable PDF in Node.js with built-in fetch
- Convert an HTML form to a fillable PDF in Ruby with Net::HTTP
More with PHP + cURL extension
- 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
- Verify a fillable PDF render without opening the file
- 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