Decrypt a PDF Document With a Password in Java
Learn how to easily remove encryption from a PDF file.
Join the DZone community and get the full member experience.Join For Free
Document encryption is one of the most common methods to ensure the secure passing of information between a business and its external customers. The encryption feature is offered on all PDF files and acts as an assurance that nobody who attempts to intercept the information will be able to open it without the password, which should follow in a separate communication.
Once you receive the file it should usually be stored with the encryption intact. However, if you have an encrypted drive or store your confidential files in an encrypted container, decrypting the file becomes an option. Decryption of a file will enable the print function, which is disabled on a secured PDF, and will also ensure that documents that were downloaded online can be opened without a password in the future.
The following process will guide you through how to decrypt a PDF using our Decrypt PDF API in Java; the password is required information to complete the decryption, so no funny business allowed!
To kick things off, we will install the client with Maven by adding a reference to the repository in pom.xml:
Next, we will add a reference to the dependency:
Now we’re ready to instance the API and call the function with the following code:
To ensure the request runs smoothly, be sure to include these parameters:
- API Key – your personal API key. To retrieve your free key, head to the Cloudmersive website to register for an account and receive 800 monthly calls across our library of APIs
- Password – valid password for the PDF file
- File – the input file to perform the operation on
And that’s it! Once the command finishes, your decrypted PDF file will be available for easy opening whenever it’s needed.
Opinions expressed by DZone contributors are their own.