A PDF processor written in Go.
View the Project on GitHub pdfcpu/pdfcpu
This command fills form fields with data via JSON.
Export your form into JSON using pdfcpu form export
.
Edit value
(or values
where appropriate) for all form fields you want to fill in the exported file.
In addition to modifying value(s)
you may change the locked
status for fields.
Remove all fields which shall remain untouched.
Run pdfcpu form fill
. This will process the attributes value
and locked
only.
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
When filling radio button groups you may either provide the text or the array index as value.
Have a look at some examples.
pdfcpu form fill inFile inFileJSON [outFile]
| name | description | values
|:————————————————|:—————-|:——-
| v(erbose) | turn on logging |
| vv | verbose logging |
| q(uiet) | quiet mode |
| -o(ffline)| disable http traffic | |
| c(onf) | config dir | $path, disable
| opw | owner password |
| upw | user password |
| u(nit) | display unit | po(ints),in(ches),cm,mm
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 |
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