Fill Form Fields
This guide will show you how to enter values for the form fields in a PDF document by using data in JSON format. The output PDF is a filled and flattened form whose content cannot be edited.
You can also fill forms with custom font using data from a JSON input file.
This snippet will fill form fields named
full_name with the value
Roy M. Ferrell amd
address-line_1 with the value
Lane 3, Felicity Avenue, Sesch.
"value": "Roy M. Ferrell"
"value": "Lane 3, Felicity Avenue, Sesch"
Before you begin
You should get your API key from your UniCloud account.
If you are using the UniPDF SDK for the first time, follow this guide to set up a local development environment.
Clone the project repository
In your terminal, clone the examples repository. It contains the Go code we will be using for this guide.
git clone https://github.com/unidoc/unipdf-examples.git
Navigate to the
forms folder in the unipdf-examples directory.
How it works
9-17 import the UniPDF packages and other required dependencies.
The init function Lines
19-26 authenticate your request with your
The main function in lines
29-78 validates your input and passes them as arguments to the
82-138 define the
fillFields function, which takes
outputPath as parameters. The function gets the form field data and values from the
jsonPath, uses them to fill the form in the
inputPath, and then saves the flattened form to the
Run the code
Run this command to fill a PDF form with a JSON input file. This will also install the required dependencies to run the program.
go run pdf_form_fill_json.go input.pdf fill.json output.pdf