We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Protect the document

hi tahir.manzoor,
I used your method, but the entire document is limited to editing including the body.
This is my code. Can you help me.
lib/aspose-words-20.6-jdk17.jar

DocumentBuilder builder = new DocumentBuilder(document);
//addWatermark
//center
insertWatermarkText(document, waterMark,“center”);
//top
insertWatermarkText(document, waterMark,“top”);
//bottom
insertWatermarkText(document, waterMark,“bottom”);
builder.moveToDocumentStart();
builder.startEditableRange();
builder.moveToDocumentEnd();
builder.endEditableRange();
document.protect(ProtectionType.READ_ONLY);
if (filePath.endsWith(“wps”)) {
document.save(outPath, SaveFormat.DOCX);
} else {
document.save(outPath);
}

@lifan

It would be great if you please attach following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a simple Java application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

@tahir.manzoor
hi, I want the text to be editable, but the watermark is not。But in my tests, the text could not be edited.
Attached are my test codes and files.
asposeWord.zip (20.7 KB)

@lifan

Please use following code example to get the desired output. Hope this helps you.

Document document = new Document(MyDir + "test.docx");

TextWatermarkOptions options = new TextWatermarkOptions();
options.setFontFamily("Arial");
options.setFontSize(36);
options.setColor(Color.BLACK);
options.setLayout(WatermarkLayout.HORIZONTAL);
options.isSemitrasparent(false);

document.getWatermark().setText("Test", options);


DocumentBuilder builder = new DocumentBuilder(document);

builder.moveToDocumentStart();
builder.startEditableRange();
builder.moveToDocumentEnd();
builder.endEditableRange();
document.protect(ProtectionType.READ_ONLY);
document.save(MyDir+ "20.6.docx");

@tahir.manzoor
hi,I have copied your code, but the whole document is still uneditable。

@lifan

Please ZIP and attach your problematic and expected output Word documents here for our reference.

Please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.

@tahir.manzoor
hi,this is output file. testOut.zip (12.4 KB)
The whole document is still uneditable

@lifan

The body of document is editable except the header that contains the watermark. Please check the attached screenshot. editable document.png (14.8 KB)