May 6, 2020

1 min read

How to get PDF annotations including comments in Python

In today’s post, we are laying out the foundation for retrieving annotations from PDF documents. We are going to make this trivial for you Python users out there by taking good advantage of an API function that is right on point. Here’s how it goes.

First step, install the client.

pip install cloudmersive-convert-api-client

And afterward, we shall instantiate the PDF editing API with our key, followed by making our function call. All that the API needs from you now is the file path.

from __future__ import print_functionimport timeimport cloudmersive_convert_api_clientfrom 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))input_file = '/path/to/file' # file | Input file to perform the operation on.try:# Get PDF annotations, including comments in the documentapi_response = api_instance.edit_pdf_get_annotations(input_file)pprint(api_response)except ApiException as e:print("Exception when calling EditPdfApi->edit_pdf_get_annotations: %s\n" % e)

Done! Yup, you just saved yourself a ton of time.