pdfcpu

Logo

A PDF processor written in Go.

View the Project on GitHub pdfcpu/pdfcpu


Changelog

Fill form via JSON

This command fills form fields with data via JSON.

  1. Export your form into JSON using pdfcpu form export.

  2. Edit value (or values where appropriate) for all form fields you want to fill in the exported file.

  3. In addition to modifying value(s) you may change the locked status for fields.

  4. Remove all fields which shall remain untouched.

  5. Run pdfcpu form fill. This will process the attributes value and locked only.

Note

pdfcpu generates all appearance streams for form fields, but if you do have form field display issues then the following configuration option may help: needAppearances: true

Have a look at some examples.

Usage

pdfcpu form fill inFile inFileJSON [outFile]


Common Flags

name description values
v(erbose) turn on logging  
vv verbose logging  
q(uiet) quiet mode  
u(nit) display unit po(ints),in(ches),cm,mm
c(onf) config dir $path, disable
upw user password  
opw owner password  


Arguments

name description required
inFile PDF input file containing form yes
inFileJSON JSON input file with form data yes
outFile PDF output file for dry runs no


Examples

Use an exported JSON file to fill firstName and dob and make dob read-only:

Field identification may be processed via “id” or “name”.

We edit the JSON file:

{
	"header": {
		"source": "english.pdf",
		"version": "pdfcpu v0.4.1",
		"creation": "2023-04-04 20:22:17 CET",
		"producer": "pdfcpu v0.4.1"
	},
	"forms": [
			"textfield": [
				{
					"name": "firstName",
					"value": "Horst",
					"locked": false
				}
			],
			"datefield": [
				{
					"name": "dob",
					"value": "31.12.1999",
					"locked": true
				}
			],
		}
	]
}

We trigger (a dry run for) form filling and write the filled form to tmp.pdf:

$ pdfcpu form fill english.pdf english.json tmp.pdf

We check the result by exporting the form out of tmp.pdf:

$ pdfcpu form export tmp.pdf tmp.json
writing tmp.json...
$ pdfcpu form fill english.pdf english.json