Parse TextBox, CheckBox, RadioButton, ComboBox fields in PDF using Java Cloud REST API

pdf form preview

Form fields are one of the integral components when dealing with customer data. It’s easy to share the PDF Acro forms with users so that they can fill the forms with data of their choice and send it back. A variety of form fields can be used but among all these, TextBox, CheckBox, RadioButton, and ComboBoxes are very common. Once the data has been filled in Acro forms, these forms can be parsed at the back office to extract data from them and save them into FDF, XML, or directly into databases.

Though all the operations including PDF forms creation, form fields addition, form fields update activity can be performed manually, when dealing with a huge set of documents, the manual operation does not seem to be feasible because its time consuming and error-prone due to manual handling of data. So automatic routines through programming language can be a viable solution. Therefore, when creating a program, we get an option to either to use an on-premises solution/API which can help us to accomplish all the requirements or, use cloud-hosted REST APIs to perform all the required tasks.

The RESTful APIs get a leap here because you do not need to manually keep track of all API versions, you do not need to keep your system updated with API versions, you do not need to worry about compatibility issues of the APIs with a certain programming language, etc. So, we present you with Aspose.PDF Cloud SDK for Java which provides you the capabilities to create, manipulate as well as transform PDF documents to other supported file formats. The Java SDK is developed on top of Aspose.PDF Cloud REST APIs which can easily be accessed using cURL commands and the SDKs are developed to facilitate our customers using a particular programming language. In this blog, we are going to shed some light on the following topics

Read, Add or update TextBox fields

The API offers three ways to read information associated with TextBox fields.

APITypeDescriptionSwagger Link
/pdf/{name}/fields/textboxGETRead document TextBox fieldsGetDocumentTextBoxFields
/pdf/{name}/page/{pageNumber}/fields/textboxGETRead document TextBox fields for a give pageGetPageTextBoxFields
/pdf/{name}/fields/textbox/{fieldName}GETRead document TextBox fields by a field nameGetTextBoxField

cURL command to read TextBox fields

Since the files are stored in your personal cloud storage, so you need to first generate a JWT authentication token which requires your personalized Client ID and Client Secret.

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=xxxx&client_secret=xxxx" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
curl -X GET "https://api.aspose.cloud/v3.0/pdf/FormDataTextBox.pdf/fields/textbox" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>"

Sample FormDataTextBox.pdf used in above example.

Java

Read, Add or update CheckBox fields

When dealing with CheckBoxes, the API also provides the capabilities to read CheckBox values, add a new checkbox or update the properties associated with an existing checkbox on PDF form.

cURL command to read CheckBox on page 1

curl -X GET "https://api.aspose.cloud/v3.0/pdf/FormDataTextBox.pdf/page/1/fields/checkbox" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>"

CURL command to update CheckBox on Page 1

curl -X PUT "https://api.aspose.cloud/v3.0/pdf/FormDataTextBox.pdf/fields/checkbox/Check%20Box1" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>" \
-H "Content-Type: application/json" \
-d "{ \"Links\": [ { \"Href\": \"string\", \"Rel\": \"string\", \"Type\": \"string\", \"Title\": \"string\" } ], \"PartialName\": \"Aspose CheckBox\", \"FullName\": \"Aspose CheckBox\", \"Rect\": { \"LLX\": 88.3573, \"LLY\": 687.617, \"URX\": 97.0198, \"URY\": 695.413 }, \"Value\": \"null\", \"PageIndex\": 1, \"Height\": 12, \"Width\": 12, \"ZIndex\": 0, \"IsGroup\": false, \"IsSharedField\": true, \"Flags\": [ \"Default\" ], \"Color\": { \"A\": 0, \"R\": 150, \"G\": 120, \"B\": 0 }, \"Contents\": \"Field Updated\", \"Margin\": { \"Left\": 0, \"Right\": 0, \"Top\": 0, \"Bottom\": 0 }, \"Highlighting\": \"None\", \"HorizontalAlignment\": \"Left\", \"VerticalAlignment\": \"Center\", \"Border\": { \"Width\": 1, \"EffectIntensity\": 1, \"Style\": \"Solid\", \"Effect\": \"None\", \"Dash\": { \"On\": 1, \"Off\": 2 }, \"Color\": { \"A\": 255, \"R\": 120, \"G\": 120, \"B\": 0 } }, \"AllowedStates\": [ \"Yes\",\"Off\" ], \"Style\": \"Circle\", \"ActiveState\": \"On\", \"Checked\": true, \"ExportValue\": \"Yes\"}"

Request URL

https://api.aspose.cloud/v3.0/pdf/FormDataTextBox.pdf/fields/checkbox/Check%20Box1

Java

Once the command/code is executed, the properties associated with checkbox 1 field are updated as shown in image below.

Preview of updated checkbox field
Image 1:- Preview of updated checkbox 1 using cURL command

Read, Add or update RadioButton fields

Similar to TextBox and CheckBox fields, the SDK provides the capabilities to read as well as update RadioButton fields on PDF document.

cURL command to read RadioButton fields on PDF document

curl -X GET "https://api.aspose.cloud/v3.0/pdf/FormDataTextBox.pdf/fields/radiobutton" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>"

Request URL

https://api.aspose.cloud/v3.0/pdf/FormDataTextBox.pdf/fields/radiobutton

Read, Add or update ComboBox fields

ComboBox manipulation is also very handy with the help of Aspose.PDF Cloud SDK for Java. You get the option to read existing ComboBox fields on document, add new ComboBox field or update an existing ComboBox.

cURL command to read all ComboBox fields

curl -X GET "https://api.aspose.cloud/v3.0/pdf/FormDataTextBox.pdf/fields/combobox" \
-H "accept: application/json" \
-H "authorization: Bearer <JWT Token>"

Request URL

https://api.aspose.cloud/v3.0/pdf/FormDataTextBox.pdf/fields/combobox

Conclusion

As explained in article above, the Form fields processing has become quite easy with the help of Cloud APIs. Furthermore, you may consider going through a related blog Form Parser | Form Recognizer | PDF Filling | Automate form processing with REST Web API