Pagecraft

fill-form

Fill a PDF form

Put answers into a document’s form fields and save it filled in.

Reads
a PDF form — application/pdf
Writes
one file — PDFs
Tool page
/fill-pdf-form

Example

Answer a form from a record you already hold.

Given

  • application.pdf — a PDF carrying form fields

From code

            import { loadDocument, runOperation } from '@pagecraft/core';

const application = await loadDocument({ bytes, name: 'application.pdf' });

const [output] = await runOperation('fill-form', [application], {
  values: {
    fullName: 'Priya Nair',
    agreed: true,
  },
});
          

From a shell

            pagecraft fill-form application.pdf --values '{"fullName":"Priya Nair","agreed":true}'
          

What comes back

One PDF of 1 page, containing “Priya Nair”.

This example is run by the test suite. If it stopped being true, the build would fail.

Options

values--values

JSON

Answers

What each field should hold, by field name. Run List PDF form fields first to see the names.

fontFile--font-file

Uint8Array

Font file

A TrueType or OpenType font, for text in a script the built-in fonts cannot draw.

What it cannot do

  • A value a field cannot hold is refused rather than written: an option a chooser does not offer, text longer than the field takes, a word in a tick box.
  • Every box is drawn as well as recorded, so the answers show in any reader rather than only in the ones that redraw a form for themselves.
  • A font file you supply is used as you chose it. Otherwise the form’s own typeface is kept, where it is one of the fourteen every reader has — a form set in a font it embeds is filled in a fallback face, which may not look identical.
  • A field the form’s author locked is filled like any other. The lock is a note to the person at the keyboard, not something the file enforces.
  • A signature field is not filled here, and a push button holds nothing to fill.
  • The answers can still be changed by whoever receives the document. Run Flatten to bake them in.