How to decrypt a PDF File and Disable its Password in Node.JS

Cloudmersive
1 min readApr 23, 2020

Today we are looking at setting up PDF decryption. If you are cringing in anticipation of this task, you are certainly not alone. While it may not be fun, we can at least make it very easy. Here’s how.

We start off with client installation, like this.

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

On the heels of that, we can call our PDF decryption function, editPdfDecrypt:

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 password = "password_example"; // String | Valid password for the PDF filevar 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.editPdfDecrypt(password, inputFile, callback);

Would you look at that, we are actually done already. Not as bad as you expected, huh?

--

--

Cloudmersive

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