Protecting Word documents

View as Markdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Watermark MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-watermark -- dnx GroupDocs.Watermark.Mcp --yes
Folders, licensing and more →

Since version 18.6, GroupDocs.Watermark provides a simplified way of protecting the Word documents with the password. The API allows you to 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.

The protection types are added to the WordProcessingProtectionType enum. Following code samples demonstrate how to protect and unprotect Word documents.

Protecting a document

Following code sample protects a Word document with the password.

advanced_usage.add_watermarks_to_word_processing.WordProcessingProtectDocument

WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();                                   
// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\document.docx"
Watermarker watermarker = new Watermarker("document.docx", loadOptions);                          
                                                                                                           
WordProcessingContent content = watermarker.getContent(WordProcessingContent.class);                       
                                                                                                           
content.protect(WordProcessingProtectionType.ReadOnly, "7654321");                                         
                                                                                                           
watermarker.save("document.docx");                                                               
                                                                                                           
watermarker.close();                                                                                       

Unprotecting a document

The following code sample shows how to unprotect a Word document regardless of password.

advanced_usage.add_watermarks_to_word_processing.WordProcessingUnProtectDocument

WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();                                   
// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\document.docx"
Watermarker watermarker = new Watermarker("document.docx", loadOptions);                          
                                                                                                           
WordProcessingContent content = watermarker.getContent(WordProcessingContent.class);                       
                                                                                                           
content.unprotect();                                                                                       
                                                                                                           
watermarker.save("document.docx");                                                               
                                                                                                           
watermarker.close();                                                                                       
Close

Ask anything about this page — the answer is based on its content.

Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.