Can't remove watermark from word document

We can add text watermark using ASPOSE Word in word file programmatically in C# console application. But we are facing issue while removing the watermark from the file.

We tried below code to remove watermark from file but it’s not working:

Document doc = new Document(filePath);
if (doc.Watermark.Type == WatermarkType.Text)
{
   doc.Watermark.Remove();
}
doc.Save(filePath);

Also attaching the word document in which it’s not working.

Test Document.docx (47.4 KB)

Please provide some insights.

@dikesh.gandhi In your document “Draft” text is not a watermark but a WordArt shape in header. You could use the following code to remove it:

Document doc = new Document(filePath);

foreach (Section section in doc.Sections)
    foreach (HeaderFooter headerFooter in section.HeadersFooters)
        foreach (Shape shape in headerFooter.GetChildNodes(NodeType.Shape, true))
            if(shape.IsWordArt)
                shape.Remove();

doc.Save(filePath);
1 Like

Thanks it’s working as expected.

Though, I would like to share my findings:

  • We use this code mentioned here to add a watermark.
  • After programmatically adding watermark in word file, if user edits the document in word application, it sets this watermark as a WordArt. Is there anything specific reason behind this?

@dikesh.gandhi Watermark is a shape in header with specific Name attribute value (WordArt shape for text watermark to be precise). Both Aspose.Words and MS Word recognize watermarks by this attribute. If you insert a text watermark in Aspose.Words by the Document.Watermark.SetText method, the name attribute value will be specified as expected. This watermark could be removed from the document by Document.Watermark.Remove() method. Also this document could be edited in MS Word and watermark name attribute will be preserved.

how aspose’s watermark placed? in shape or in image?

@NensonM If you need to place text watermark it is inserted as WordArt Shape, please see Document.Watermark.SetText method. If it is required to insert an image watermark it is inserted as an Image Shape, see Document.Watermark.SetImage.