Locking watermark in word processing document
Leave feedback
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 when 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.
setLockType() method has been added to WordProcessingWatermarkBaseOptions class (and all descendants) to set any of the above-mentioned lock types. WordProcessingLockType enum is used to define the lock type. The following code samples show how to lock watermark in different scenarios.
WordProcessingLoadOptionsloadOptions=newWordProcessingLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\document.docx"
Watermarkerwatermarker=newWatermarker("document.docx",loadOptions);TextWatermarkwatermark=newTextWatermark("Watermark text",newFont("Arial",19));watermark.setForegroundColor(Color.getRed());WordProcessingWatermarkPagesOptionsoptions=newWordProcessingWatermarkPagesOptions();options.setLocked(true);options.setLockType(WordProcessingLockType.AllowOnlyFormFields);// To protect with password
//options.setPassword("7654321");
watermarker.add(watermark,options);watermarker.save("document.docx");watermarker.close();
WordProcessingLoadOptionsloadOptions=newWordProcessingLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\document.docx"
Watermarkerwatermarker=newWatermarker("document.docx",loadOptions);TextWatermarkwatermark=newTextWatermark("Watermark text",newFont("Arial",19));watermark.setForegroundColor(Color.getRed());WordProcessingWatermarkPagesOptionsoptions=newWordProcessingWatermarkPagesOptions();options.setPageNumbers(newint[]{1,3});options.setLocked(true);options.setLockType(WordProcessingLockType.AllowOnlyComments);// To protect with password
//options.Password = "7654321";
watermarker.add(watermark,options);watermarker.save("document.docx");watermarker.close();
WordProcessingLoadOptionsloadOptions=newWordProcessingLoadOptions();// Specify an absolute or relative path to your document. Ex: "C:\\Docs\\document.docx"
Watermarkerwatermarker=newWatermarker("document.docx",loadOptions);TextWatermarkwatermark=newTextWatermark("Watermark text",newFont("Arial",19));watermark.setForegroundColor(Color.getRed());WordProcessingWatermarkSectionOptionsoptions=newWordProcessingWatermarkSectionOptions();options.setSectionIndex(0);options.setLocked(true);options.setLockType(WordProcessingLockType.ReadOnlyWithEditableContent);// To protect with password
//options.setPassword("7654321");
watermarker.add(watermark,options);watermarker.save("document.docx");watermarker.close();
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.