Protecting word processing documents

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, 119 KB)

Download full output

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

Unprotect a document

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

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

if __name__ == "__main__":
    unprotect_document()

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

Binary file (DOCX, 118 KB)

Download full output

Close
Loading

Analyzing your prompt, please hold on...

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