How to get PDF annotations including comments in Node.JS
2 min readMay 7, 2020
In this post I am going to show you how to use Node.JS to get all of the annotations from a given PDF document, and it’s only going to require a couple minutes of your time.
Let’s setup our client first:
npm install cloudmersive-convert-api-client --save
Moving on, create a new instance of the edit PDF API, which contains editPdfGetAnnotations.
var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.EditPdfApi();var inputFile = "/path/to/file"; // File | Input file to perform the operation on.var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.editPdfGetAnnotations(inputFile, callback);
Your annotations will then be returned to you in this format:
{
"Successful": true,
"Annotations": [
{
"Title": "string",
"AnnotationType": "string",
"PageNumber": 0,
"AnnotationIndex": 0,
"Subject": "string",
"TextContents": "string",
"CreationDate": "2020-05-07T02:43:34.747Z",
"ModifiedDate": "2020-05-07T02:43:34.747Z",
"LeftX": 0,
"TopY": 0,
"Width": 0,
"Height": 0
}
]
}
And it’s as easy as that!