Protecting word processing documents

View as MarkdownMarkdown

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 →

Beyond locking an individual watermark, you can protect the whole document. Watermarker.get_content() returns a WordProcessingContent with protect() and unprotect() methods.

Protect a document

The example sets read-only protection with a password.

from groupdocs.watermark import Watermarker
from groupdocs.watermark.options.word_processing import WordProcessingLoadOptions
from groupdocs.watermark.contents.word_processing import WordProcessingProtectionType

def protect_document():
    with Watermarker("./document.docx", WordProcessingLoadOptions()) as watermarker:
        content = watermarker.get_content()
        content.protect(WordProcessingProtectionType.READ_ONLY, "p@ssw0rd")
        watermarker.save("./output.docx")

if __name__ == "__main__":
    protect_document()

document.docx is the sample file used in this example. Click here to download it.

Binary file (DOCX, 223 KB)

Download full output

Available WordProcessingProtectionType values: READ_ONLY, ALLOW_ONLY_FORM_FIELDS, ALLOW_ONLY_COMMENTS, and ALLOW_ONLY_REVISIONS.

Unprotect a document

unprotect() removes the protection without asking for its password. The sample below is a read-only protected document.

from groupdocs.watermark import Watermarker
from groupdocs.watermark.options.word_processing import WordProcessingLoadOptions

def unprotect_document():
    with Watermarker("./protected-document.docx", WordProcessingLoadOptions()) as watermarker:
        content = watermarker.get_content()
        content.unprotect()
        watermarker.save("./output.docx")

if __name__ == "__main__":
    unprotect_document()

protected-document.docx is the sample file used in this example. Click here to download it.

Binary file (DOCX, 223 KB)

Download full output