Created
November 11, 2020 02:06
-
-
Save aspose-com-gists/4351f6ce87d8aaa77ceee87609e9302a to your computer and use it in GitHub Desktop.
Protect or Unprotect MS Word DOCX Files 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
// Load a DOCX file | |
Document doc = new Document("word.docx"); | |
// Protect with a protection type | |
doc.protect(ProtectionType.ALLOW_ONLY_COMMENTS); | |
// Save the document | |
doc.save("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
// Load a DOCX file | |
Document doc = new Document("word.docx"); | |
String password = "123456"; | |
// Protect with a protection type | |
doc.protect(ProtectionType.ALLOW_ONLY_COMMENTS, password); | |
// Save the document | |
doc.save("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
// Load a DOCX file | |
Document doc = new Document("word.docx"); | |
// Unprotect | |
doc.unprotect(); | |
// Save the document | |
doc.save("Unlocked Document.docx"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment