How to get PDF annotations including comments in C# .NET Framework

Cloudmersive
2 min readFeb 8, 2020

--

Need a quick way to extract annotation info from a PDF file? Well, look no further. This lightning fast tutorial will have you up and running in no time.

Let’s begin by installing our API Client via Package Manager.

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 2.2.0

Now we can call EditPdfGetAnnotations and provide it with a PDF file.

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;namespace Example{public class EditPdfGetAnnotationsExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new EditPdfApi();var inputFile = new System.IO.Stream(); // System.IO.Stream | Input file to perform the operation on.try{// Get PDF annotations, including comments in the documentGetPdfAnnotationsResult result = apiInstance.EditPdfGetAnnotations(inputFile);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling EditPdfApi.EditPdfGetAnnotations: " + e.Message );}}}}

The API will return the annotations to us in this format:

{
"Successful": true,
"Annotations": [
{
"Title": "string",
"AnnotationType": "string",
"PageNumber": 0,
"AnnotationIndex": 0,
"Subject": "string",
"TextContents": "string",
"CreationDate": "2020-02-08T04:09:02.524Z",
"ModifiedDate": "2020-02-08T04:09:02.524Z",
"LeftX": 0,
"TopY": 0,
"Width": 0,
"Height": 0
}
]
}

And that’s a wrap. If you are looking for this same approach to similar issues such as document editing and format conversion, be sure to take a look at our documentation for more useful functions.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet