Related blog post: Lock & Unlock Word Documents in Java
Last active
February 7, 2022 10:52
-
-
Save GroupDocsGists/7896b4529c25d419b78b95469e8fe257 to your computer and use it in GitHub Desktop.
Password Protection of Word Files in Java by Adding, Removing, and Changing Passwords
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
/* | |
* Password Protect Word Documents in Java | |
*/ | |
AddPasswordOptions addOptions = new AddPasswordOptions("mySECRETpassWORD"); | |
Merger merger = new Merger("path/document.docx"); | |
merger.addPassword(addOptions); | |
merger.save("path/protected-document.docx"); |
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
/* | |
* Change password of the protected DOC/DOCX documents in Java | |
*/ | |
LoadOptions loadOptions = new LoadOptions("mySECRETpassWORD"); | |
UpdatePasswordOptions updateOptions = new UpdatePasswordOptions("TOPSECRET_pa22WORD"); | |
Merger merger = new Merger("path/protected-document.docx", loadOptions); | |
merger.updatePassword(updateOptions); | |
merger.save("path/pwd-changed-document.docx"); |
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 from Word document in Java | |
*/ | |
LoadOptions loadOptions = new LoadOptions("mySECRETpassWORD"); | |
Merger merger = new Merger("path/protected-document.docx", loadOptions); | |
merger.removePassword(); | |
merger.save("path/no-pwd-document.docx"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment