Skip to content
huzpsb edited this page Nov 8, 2026 · 2 revisions

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

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

Mutate

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

Export → fill

hspdf form export in.pdf                 # writes in.json
# edit values in in.json, optionally trim entries down to id/name + value
hspdf 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):

hspdf form multifill in.pdf in.json outDir             # one PDF per instance
hspdf 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/hspdf/pkg/api"
	"github.com/huzpsb/hspdf/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