How to Decrypt, Unlock Password-Protected PDF using PHP

Cloudmersive
2 min readFeb 21, 2023

--

If your application processes a lot of secured PDF documents, downloading & applying a password to each one will take up a lot of time that you (and your application users) probably don’t have. Thankfully, the free-to-use API provided below will make it easy to automate this process with an efficient external service, automatically processing secured PDFs alongside their passwords to return a decrypted PDF file. It’s super easy to use this API in your project — just follow steps to copy & paste ready-to-run PHP code examples below, and you’ll be done in minutes.

First things first, run this command to install the SDK:

composer require cloudmersive/cloudmersive_document_convert_api_client

Next, include the remaining code examples, and supply a free-tier API key to authorize your request (to get one, register a free account on our website):

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');



$apiInstance = new Swagger\Client\Api\EditPdfApi(


new GuzzleHttp\Client(),
$config
);
$password = "password_example"; // string | Valid password for the PDF file
$input_file = "/path/to/inputfile"; // \SplFileObject | Input file to perform the operation on.

try {
$result = $apiInstance->editPdfDecrypt($password, $input_file);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling EditPdfApi->editPdfDecrypt: ', $e->getMessage(), PHP_EOL;
}
?>

Just like that, you’re already done!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet