How to Automatically Encrypt and Password-Protect a PDF

Are you generating a lot of new PDFs, and dreading the tedious task of securing them? Never fear — with our PDF Encryption API, you can automatically set an owner password to control editor/creator permissions, and set another user/reader password to control PDF viewership. You may also, of course, set the password fields to “null” to omit the given password if you prefer.

With the JavaScript code examples provided below, you can easily structure your API call and put your PDF protection worries aside. To authenticate API access, quickly register a free account on our website to receive your API key.

Let’s get started. First, run the below command to install jQuery:

bower install jquery

After that, use the below snippet to input your PDF file:

var form = new FormData();
form.append("inputFile", fileInput.files[0], "file");

Now you’re only one step away: copy in the below code block to complete the API call, and include your API key where indicated in the code:

var settings = {
"url": "https://api.cloudmersive.com/convert/edit/pdf/encrypt",
"method": "POST",
"timeout": 0,
"headers": {
"userPassword": "<string>",
"ownerPassword": "<string>",
"encryptionKeyLength": "<string>",
"Content-Type": "multipart/form-data",
"Apikey": "YOUR-API-KEY-HERE"
},
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
});

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cloudmersive

Cloudmersive

437 Followers

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