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

Free Support Forum - aspose.com

doc.Watermark.SetText() is using duplicate shape ids

I have found what looks like a bug with Aspose.Words for .NET. We are using Aspose.Words.Document.Watermark.SetText() and it appears three headers are implicitly created: One for default, one for first page, and one for even pages: (I’m using the Open XML SDK Productivity Tool just for viewing the components of the document)
image.png (86.0 KB)

The problem is each watermark shape has an id of PowerPlusWaterMarkObject100001. When the document is opened in desktop Microsoft Word, it “fixes” the duplicates by changing the ids to something else. As a result, calling Aspose.Words.Document.Watermark.Remove() doesn’t remove all of the watermarks. I attached a screenshot where you can see the shape id before Word modifies it:
image.png (81.7 KB)

here is a screenshot after Word modifies it:
image.png (82.4 KB)

I’m also attaching the original document with the duplicate ids:duplicateids.docx (13.0 KB)

And here is the document that has been changed:
corrputed.docx (18.1 KB)

@tstowell Thank you for reporting this problem to use. I have logged it as WORDSNET-23231. We will keep you informed and let you know once it is resolved.
As a temporary workaround you can try using code like the following:

Document doc = new Document();
doc.Watermark.SetText("Watermark");

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
int counter = 0;
foreach (Shape s in shapes)
{
    if (s.Name == "PowerPlusWaterMarkObject100001")
        s.Name = string.Format("{0}{1}", s.Name, counter++);
}

doc.Save(@"C:\Temp\out.docx");
1 Like

The issues you have found earlier (filed as WORDSNET-23231) have been fixed in this Aspose.Words for .NET 22.1 update also available on NuGet.

1 Like