How to fill PDF Form Field Values in Python

Cloudmersive
1 min readApr 25, 2020

--

Here is a super useful API function, one that will allow you to populate PDF forms with data. It functions best when paired with its sister function, edit_pdf_get_form_fields, which provides the form fields in an input form.

We can start out by using pip install to import our client data.

pip install cloudmersive-convert-api-client

Next call edit_pdf_set_form_fields.

from __future__ import print_functionimport timeimport cloudmersive_convert_api_clientfrom cloudmersive_convert_api_client.rest import ApiExceptionfrom pprint import pprint# Configure API key authorization: Apikeyconfiguration = cloudmersive_convert_api_client.Configuration()configuration.api_key['Apikey'] = 'YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['Apikey'] = 'Bearer'# create an instance of the API classapi_instance = cloudmersive_convert_api_client.EditPdfApi(cloudmersive_convert_api_client.ApiClient(configuration))field_values = cloudmersive_convert_api_client.SetPdfFormFieldsRequest() # SetPdfFormFieldsRequest |try:# Sets ands fills PDF Form field valuesapi_response = api_instance.edit_pdf_set_form_fields(field_values)pprint(api_response)except ApiException as e:print("Exception when calling EditPdfApi->edit_pdf_set_form_fields: %s\n" % e)

And that’s it, folks! Pat yourself on the back, because it’s all over. Know that our APIs offer a ton of other great functions just like this, so check them out!

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.