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