Protect and Unprotect Word Documents with Watermark in Java

GroupDocs Watermark for .NETAnother monthly release of GroupDocs.Watermark for Java is onboard. GroupDocs.Watermark for Java 18.6 supports locking of watermarks in Word documents. Furthermore, it also provides the ability to protect and unprotect the Word documents. Following are the details about the new features added in version 18.6.

Lock Watermark in Word Documents

There might be the case when you need to lock the watermarks in a Word document to restrict the editing. To deal with such cases, GroupDocs.Watermark provides 5 variants of locking Word document after adding watermark.
  • AllowOnlyRevisions: user can only add revision marks to the document.
  • AllowOnlyComments: user can only modify comments in the document.
  • AllowOnlyFormFields: the document is split into one-page sections and locked section with watermark is added between each two adjacent document sections.
  • ReadOnly: the entire document is read-only.
  • ReadOnlyWithEditableContent: the document is read-only, but all the content except the watermark is marked as editable.
The following code sample shows how to lock watermark in a Word document.
String inputFileName = "d:\\input.docx";
String outputFileName = "d:\\output.docx";
 
WordsDocument doc = Document.load(WordsDocument.class, inputFileName);
 
TextWatermark watermark = new TextWatermark("Watermark text", new Font("Arial", 19));
watermark.setForegroundColor(Color.getRed());
 
WordsShapeSettings settings = new WordsShapeSettings();
settings.setLocked(true);
settings.setLockType(WordsLockType.AllowOnlyFormFields);
settings.setPassword("7654321");
 
doc.addWatermark(watermark, settings);
 
doc.save(outputFileName);
doc.close();
For more details on this feature, please visit this documentation article.

Protect/Unprotect Word Documents

GroupDocs.Watermark provides a simplified way of protecting the Word documents with the password. You can protect as well as unprotect the Word documents. The following protection types are supported:
  • AllowOnlyRevisions: user can only add revision marks to the document.
  • AllowOnlyComments: user can only modify comments in the document.
  • AllowOnlyFormFields: user can only enter data in the form fields in the document.
  • ReadOnly: no changes are allowed to the document.

Protect a Word Document

The following code sample shows how to protect a Word Document.
WordsDocument doc = Document.load(WordsDocument.class, "D:\\test.doc");
doc.protect(WordsProtectionType.ReadOnly, "7654321");
doc.save("D:\\test.doc");
doc.close();

Unprotect a Word Document

The following code sample shows how to unprotect a Word Document.
WordsDocument doc = Document.load(WordsDocument.class, "D:\\test.doc");
doc.unprotect();
doc.save("D:\\test.doc");
doc.close();
For more details on this feature, please visit this documentation article.

Available Channels and Resources

Feedback

As always, if you have any questions or suggestions, feel free to write on our forum.