Guides · Node.js · built-in fetch
Get a fillable PDF of just the form — no nav, no footer in Node.js with built-in fetch
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 Node.js program using built-in fetch, 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.
import { writeFile } from "node:fs/promises";
const res = await fetch("https://snapdok.io/v1/render", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.SNAPDOK_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
url: "https://your-app.com/intake-form",
format: "pdf",
pdf_forms: true,
pdf_form_only: true,
}),
});
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
await writeFile("form-only.pdf", Buffer.from(await res.arrayBuffer()));
console.log(res.headers.get("x-form-extracted"), "// true = pruned to the form; false = full page");
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 built-in fetch
No dependency needed: fetch is global from Node 18 onward (snapdok's own test suite uses it). The binary-safety detail is res.arrayBuffer() → Buffer.from(...) — reaching for res.text() is the classic way to corrupt a PDF in Node. fetch does not reject on HTTP error statuses, so the res.ok check is load-bearing: without it, an expired key writes a 40-byte JSON error to disk with a .pdf extension.
Response headers worth reading
| Header | Meaning |
|---|---|
X-Form-Extracted | true when the prune happened, false on fallback. |
X-Form-Extract-Fallback | Why extraction fell back, when it did. |
X-Form-Fields | Fields placed either way. |
Full parameter reference: the docs. Hard numbers on caps and timeouts: limits.
Related guides
Same task, other stacks
- Get a fillable PDF of just the form — no nav, no footer in Python with requests
- Get a fillable PDF of just the form — no nav, no footer in PHP with cURL extension
- Get a fillable PDF of just the form — no nav, no footer in Ruby with Net::HTTP
More with Node.js + built-in fetch
- Convert an HTML form to a fillable PDF
- 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