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.
Sample input

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.
[
{
"name": "full_name",
"value": "Roy M. Ferrell"
},
{
"name": "address_line_1",
"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.
cd unipdf-examples/forms
How it works
Lines 9-17 import the UniPDF packages and other required dependencies.
The init function Lines 19-26 authenticate your request with your UNIDOC_LICENSE_API_KEY.
The main function in lines 29-78 validates your input and passes them as arguments to the fillFields function.
Lines 82-138 define the fillFields function, which takes inputPath, jsonPath, and 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 outputPath.
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
Sample output
