Inkspan › Guides › How to fill a PDF form in Node.js

How to fill a PDF form in Node.js

Tax forms, applications, and government paperwork usually arrive as AcroForm PDFs with named fields. The /v1/pdf/fill-form endpoint takes the blank form plus a JSON object mapping field names to values and returns the completed document, so you can populate official paperwork from your own data without a human retyping it.

The fields parameter is required and must be a JSON string inside a multipart request, not a nested JSON object. That encoding detail causes most first-attempt failures.

Also in: cURL · Python

Node.js example

import fs from 'node:fs';

const fd = new FormData();
fd.append('file', new Blob([fs.readFileSync('input.pdf')]), 'input.pdf');
fd.append('fields', "{\"full_name\":\"Ada Lovelace\",\"date\":\"2026-10-01\"}");

const res = await fetch('https://api.inkspan.dev/v1/pdf/fill-form', {
  method: 'POST',
  headers: { 'X-API-Key': process.env.INKSPAN_KEY },
  body: fd,
});
if (!res.ok) throw new Error(await res.text());
fs.writeFileSync('filled.pdf', Buffer.from(await res.arrayBuffer()));

Request parameters

NameTypeRequiredDescription
filefileyesThe PDF containing AcroForm fields.
fieldsstring (JSON)yesA JSON object of field name to value, sent as a string in the multipart body.

Response

Returns a PDF as a binary stream with Content-Type: application/pdf and Content-Disposition: attachment; filename=filled.pdf. Write the response body straight to disk — do not parse it as JSON.

Things that catch people out

Errors

StatusMeaningFix
401Invalid or missing API keySend your key in the X-API-Key header.
402Monthly quota exceededThe response reports used/quota. Upgrade at inkspan.dev/#pricing.
422Missing or invalid parameterCheck required fields in the table above — the body names the offending field.

Failed requests do not count against your quota; only successful ones are metered.

Frequently asked questions

How do I find the field names?

Inspect the PDF with a library such as pypdf and read the AcroForm field dictionary. The internal names frequently differ from the printed labels.

Why am I getting a 422?

Almost always a missing or malformed fields parameter. It must be present and must be a JSON string.

Are checkboxes supported?

Yes, but they take the export value defined in the form — often Yes or On rather than true.

Get a free API key →

Related Manipulate guides: merge PDF files · split a PDF into pages · compress a PDF · add a watermark to a PDF · convert a PDF to images