xfaf

Fill the PDF forms that only open in Acrobat, from JSON.

Governments and insurers still publish dynamic XFA forms, the ones that show “Please wait…” in every other viewer. xfaf reads them on a server with no Acrobat: it lists the fields, maps which field drives which, fills the form from a JSON file and writes a PDF back.

data.json

{ }
Family Information filled.pdf, section A
Name
Date of birth
Marital status:
Present address
$ xfaf fill imm5645.pdf data.json -o filled.pdf

Edit the values on the left. This panel is an illustration that runs in your browser; the field names, captions and choice codes are the ones xfaf extracts from a real Canadian immigration form.

Five commands, JSON in and out

Each one reads a PDF and prints JSON or writes a file. Output below is from real runs, shortened.

What kind of PDF is this?

Tells an XFA form from an AcroForm or a plain PDF, and counts fields and scripts before you commit to anything.

$ xfaf inspect imm5645.pdf
{
  "pdf_type": "xfa_static",
  "pages": 2,
  "xfa": {
    "fields": 151,
    "scripts": {
      "total": 44,
      "javascript": 44,
      "formcalc": 0
    }
  }
}

Built for one job

A good fit

  • You file the same government or insurer XFA form many times and fill it by hand today
  • Your data is already in a database or spreadsheet
  • You need the form's field list to build your own intake screen
  • You run on Linux, where Acrobat is not an option

Not a fit

  • Ordinary AcroForm PDFs: many free libraries already fill those
  • Viewing or printing an XFA form as it looks in Acrobat
  • Signing, submitting or validating the form for you
  • Designing new forms

Known limits

Read these before you rely on it.

No recalculation
Fill writes the values you give. It does not run the form's scripts, so computed totals are not updated and validation rules are not enforced.
FormCalc is not analysed
The logic graph covers JavaScript only. On the non-immigration sample forms, about 16% of scripts are FormCalc.
Narrow test sample
Tested on 52 forms from three Canadian government issuers. Forms from other publishers may behave differently.
Not yet checked in Acrobat
Filled values are verified by reading the PDF back with xfaf, not by opening each file in Adobe Acrobat.
A shrinking format
Adobe has deprecated XFA. xfaf exists for the forms still in circulation, not for new ones.

Install

Python 3.10 or later. Three dependencies: pikepdf, lxml and defusedxml. Node is needed only for graph.

# from a copy of the source
pip install -e .
xfaf inspect your-form.pdf

xfaf is not on PyPI yet and the source is not public yet.