Guides · PHP · cURL extension
Turn an online registration form into a fillable PDF in PHP with cURL extension
Every event eventually meets a participant who cannot — or will not — register online: no account, a locked-down work laptop, a school that wants paper on file. The usual answer is maintaining a second, Word-document copy of the form that drifts out of sync with the web one. The better answer is generating the paper copy from the web form, so there is exactly one source of truth.
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/events/spring-workshop/register",
'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('registration.pdf', $bytes);
echo ($headers['x-form-fields'] ?? '?') . " // fields on the printed form\n";
Radio groups are the detail to check on registration forms: a set of <input type="radio"> sharing a name becomes a proper PDF radio group — pick one and the others clear, same as on the page. Checkbox consents ("email me about future workshops") stay independently tickable. A <select> of ticket types becomes a dropdown in the PDF reader.
With pdf_form_only the render drops your site's navigation and prints just the form block with its headings — hand that straight to a printer. And because fields keep their HTML names, a filled copy that comes back to you can be read programmatically with any PDF library and fed into the same handler your web form posts to.
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 controls made it into the PDF. |
X-Form-Skipped | Anything skipped — compare against your form. |
X-Form-Extracted | Whether the page was pruned to the form. |
Full parameter reference: the docs. Hard numbers on caps and timeouts: limits.
Related guides
Same task, other stacks
- Turn an online registration form into a fillable PDF in Python with requests
- Turn an online registration form into a fillable PDF in Node.js with built-in fetch
- Turn an online registration form into a fillable PDF 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
- 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