Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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