List Form Fields

This guide will show you how to get all the form fields in a PDF document.

Sample input

Input Form

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 in lines 19-26 authenticates your request with your UNIDOC_LICENSE_API_KEY.

The main function in lines 28-40 validates your input and passes it as an argument to the listFormFields function.

Lines 42-212 define the listFormFields function, which accepts inputPath as a parameter. The function reads the PDF from the inputPath with the pdfReader() method and returns a list of form fields(widget annotations) on each page in the input PDF.

Run the code

Run this command to get all the form fields in a PDF. This will also install the required dependencies to run the program.

Sample output

You will get all the form fields for each page in the PDF on the terminal.

AcroForm (0xc0000de000)
 NeedAppearances: <nil>
 SigFlags: <nil>
 CO: []
 DR: &{<nil> <nil> <nil> <nil> <nil> Dict("ZaDb": IObject:42, ) <nil> <nil> 0xc0004b4300 <nil>}
 DA: <nil>
 Q: <nil>
 XFA: <nil>
 #Fields: 9
 =====
=====
Field 1
Name: full_name
 Flags: Clear (0)
 Text
 - DA: <nil>
 - '<nil>'
 Annotations: 1
 - Annotation 1 
 - Page number: 1
 - Rect: [123.970000, 619.020000, 343.990000, 633.600000]
 - wa.AS: <nil>
 - wa.AP: <nil>
 - wa.F:  4
   - Appearance dict not present: <nil>

...

=====
Field 9
Name: fav_color
 Flags: Combo (131072)
 Choice
 - '<nil>'
 Annotations: 1
 - Annotation 1 
 - Page number: 1
 - Rect: [144.520000, 461.610000, 243.920000, 476.190000]
 - wa.AS: <nil>
 - wa.AP: <nil>
 - wa.F:  4
   - Appearance dict not present: <nil>

Got any Questions?

We're here to help you.