Guides · PHP · cURL extension

Get a fillable PDF of just the form — no nav, no footer in PHP with cURL extension

A fillable PDF of a whole web page still carries the web page around it: the navigation bar, the cookie banner, the footer with forty links. Adding "pdf_form_only": true to a pdf_forms render prunes the document down to just the form — fields with their labels, the group headings, and the title directly above it. What comes out looks like the paper version of the form, not a printout of the website.

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('form-only.pdf', $bytes);
echo ($headers['x-form-extracted'] ?? '?') . " // true = pruned to the form; false = full page\n";

This flag is best-effort by design, and you should code for that. When the extractor cannot identify a form region it is sure about — no visible controls, a lone search box, a form wrapping the entire page (common on older ASP.NET sites), iframes, JavaScript widget "forms" — it falls back to the full page: the exact bytes pdf_forms alone would have produced, never a half-broken cut. The rule it is built around: better a navigation bar too many than a required field too few.

The response tells you which way it went: X-Form-Extracted: true means the PDF is the pruned form, false means the full page, with the machine reason in X-Form-Extract-Fallback. The flag is ignored unless format is "pdf" and pdf_forms is true, and it is metered as one ordinary render — no extra charge.

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

HeaderMeaning
X-Form-Extractedtrue when the prune happened, false on fallback.
X-Form-Extract-FallbackWhy extraction fell back, when it did.
X-Form-FieldsFields placed either way.

Full parameter reference: the docs. Hard numbers on caps and timeouts: limits.

Related guides

Same task, other stacks

More with PHP + cURL extension

In the wild