Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created November 11, 2020 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/4351f6ce87d8aaa77ceee87609e9302a to your computer and use it in GitHub Desktop.
Save aspose-com-gists/4351f6ce87d8aaa77ceee87609e9302a to your computer and use it in GitHub Desktop.
Protect or Unprotect MS Word DOCX Files in Java
// 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");
// 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");
// 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