How to get PDF annotations including comments in Java

Cloudmersive
1 min readFeb 13, 2020

--

You don’t need me to tell you why extracting PDF annotations is useful. Rather, you need a quick implementation method so you can get back to what really matters: wasting time on your phone! Seriously though, this is going to be very fast and easy.

First we are going to dynamically compile our API library using Jitpack. With this in mind, add these two references to your pom.xml file.

1:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

2:

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v3.34</version>
</dependency>
</dependencies>

Now that our library is ready, invoke editPdfGetAnnotations:

// Import classes://import com.cloudmersive.client.invoker.ApiClient;//import com.cloudmersive.client.invoker.ApiException;//import com.cloudmersive.client.invoker.Configuration;//import com.cloudmersive.client.invoker.auth.*;//import com.cloudmersive.client.EditPdfApi;ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");Apikey.setApiKey("YOUR API KEY");// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.setApiKeyPrefix("Token");EditPdfApi apiInstance = new EditPdfApi();File inputFile = new File("/path/to/file.txt"); // File | Input file to perform the operation on.try {GetPdfAnnotationsResult result = apiInstance.editPdfGetAnnotations(inputFile);System.out.println(result);} catch (ApiException e) {System.err.println("Exception when calling EditPdfApi#editPdfGetAnnotations");e.printStackTrace();}

Done! All of the annotations in that PDF will now be enumerated for you in the output.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet