Related blog post: Password Protection for PDF Files in Java
Last active
December 18, 2021 12:36
-
-
Save GroupDocsGists/4be8e5153e84bf9c2d55f74f11f07543 to your computer and use it in GitHub Desktop.
Password Protection of PDF Files by Adding, Removing, and Changing Password in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Add password protection to the PDF document in Java | |
*/ | |
Merger merger = new Merger("path/document.pdf"); | |
AddPasswordOptions addOptions = new AddPasswordOptions("mySECRETpassWORD"); | |
merger.addPassword(addOptions); | |
merger.save("path/protected-document.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Update password of the protected PDF document in Java | |
*/ | |
LoadOptions loadOptions = new LoadOptions("mySECRETpassWORD"); | |
UpdatePasswordOptions updateOptions = new UpdatePasswordOptions("TOPSECRET_pa22WORD"); | |
Merger merger = new Merger("path/protected-document.pdf", loadOptions); | |
merger.updatePassword(updateOptions); | |
merger.save("path/pwd-changed-document.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Remove password protection of PDF document in Java | |
*/ | |
LoadOptions loadOptions = new LoadOptions("mySECRETpassWORD"); | |
Merger merger = new Merger("path/protected-document.pdf", loadOptions); | |
merger.removePassword(); | |
merger.save("path/no-pwd-document.pdf"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment