How to Remove All the Annotations from a PDF Document using Node.js

Cloudmersive
2 min readSep 28, 2023

--

We can easily delete all the annotations & comments in a PDF document with a single, free API request using minimal code.

All we need to do is follow a few quick steps below, and we’ll be up and running in no time.

Let’s start by installing the SDK. We can do so by either running the following command:

npm install cloudmersive-convert-api-client --save

Or by including the following snippet in our package.json:

  "dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}

Now let’s grab a free-tier API key to authorize our requests. We can get one by registering a free account on the Cloudmersive website — this will allow us to make up to 800 API calls per month with no commitments.

Finally, let’s pass our PDF form into the below function. This will automatically remove PDF annotations and comments and return the encoding for our new file:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');
var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;

// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';



var apiInstance = new CloudmersiveConvertApiClient.EditPdfApi();

var inputFile = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // 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.editPdfRemoveAllAnnotations(inputFile, callback);

That’s all there is to it — no more code required!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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