Skip to content
huzpsb edited this page Oct 25, 2026 · 1 revision

Form

Manage AcroForm PDF forms: list fields, lock/unlock/reset/remove, export data, fill single instances, or batch-generate filled instances from JSON/CSV.

Command line

Discover

pdfcpu2 form list in.pdf                  # fields with name and id
pdfcpu2 form list --json in.pdf           # form export JSON (one entry per file)

Mutate

pdfcpu2 form remove in.pdf middleName birthPlace   # by id or name (mixed ok)
pdfcpu2 form lock in.pdf dateOfBirth               # make read-only
pdfcpu2 form lock in.pdf                           # whole form read-only
pdfcpu2 form unlock in.pdf                         # make writable again
pdfcpu2 form reset in.pdf firstName lastName       # reset to defaults

Export → fill

pdfcpu2 form export in.pdf                 # writes in.json
# edit values in in.json, optionally trim entries down to id/name + value
pdfcpu2 form fill in.pdf in.json out.pdf

Minimal fill JSON:

[
  {
    "name": "firstName",
    "value": "Ada"
  },
  {
    "id": 2,
    "value": "Lovelace"
  }
]

Multifill — many instances

JSON array (one object per instance) or CSV (first row = field names/ids, one row per instance):

pdfcpu2 form multifill in.pdf in.json outDir             # one PDF per instance
pdfcpu2 form multifill -m merge in.pdf in.csv outDir     # single merged PDF

Output modes: single (default, one file per instance) or merge.

Go API

package main

import (
	"context"

	"github.com/huzpsb/pdfcpu2/pkg/api"
	"github.com/huzpsb/pdfcpu2/pkg/pdfcpu/model"
)

func main() {
	ctx := context.Background()
	conf := model.NewDefaultConfiguration()

	// Lock the whole form (nil field list = all fields)
	err := api.LockFormFieldsFile(ctx, "in.pdf", "locked.pdf", nil, conf)
	if err != nil {
		panic(err)
	}

	// Fill one instance from JSON
	err = api.FillFormFile(ctx, "in.pdf", "data.json", "filled.pdf", conf)

	// Batch: one PDF per CSV record into ./out
	err = api.MultiFillFormFile(ctx, "in.pdf", "records.csv", "./out", "instance", false, conf)
	if err != nil {
		panic(err)
	}
}

More entry points: api.ListFormFields (names), api.FormFields (typed []form.Field), api.RemoveFormFieldsFile, api.UnlockFormFieldsFile, api.ResetFormFieldsFile, api.ExportFormFile(inPDF, outJSON, conf). Full syntax and more samples: pkg/api/test/form_test.go in the repository.

Clone this wiki locally