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

Free Support Forum - aspose.com

Detect a watermark on word document

Hi Team,


I want to know can we check if a word(.doc, .docx, .rtf) contains watermark.

Let me know which Aspose Words API should I use ?

I am using .Net V4.5 and Aspose.words V15.4.0.0

Regards,
Arun Chandran C

Hi Arun,


Thanks for your inquiry. A watermark in Word document is represented by a Shape node in Aspose.Words. This Shape or watermark is generally placed inside Header and you can look for any Shape nodes present in header areas as follows:

if (doc.FirstSection.HeadersFooters[HeaderFooterType.HeaderPrimary].GetChildNodes(NodeType.Shape, true).Count > 0)

{

// do something useful

}

Also, there are three types of headers/footers e.g. FooterFirst, FooterPrimary and FooterEven. Similarly we have three types of header e.g. HeaderFirst, HeaderPrimary and HeaderEven and you might want to check for Shape nodes in all headers.

I hope, this helps.

Best regards,

Hi Awais,

Thanks for your reply.
Can HeadersFooters contain any other shapes other than watermarks? If so your code will fail.
Do i need to check for Shape nodes in all headers/footers to detect watermark ?

Thanks
Arun Chandran C

Hi Arun,


Thanks for your inquiry. Yes. headers/footers can contain other Shapes in addition to watermark Shape. And yes you can check for Shape nodes in all headers/footers to detect watermark.

Best regards,


Hi Awais,

Thanks for your reply.

you can check for Shape nodes in all headers/footers to detect watermark


As you replied, how can I check for Shape nodes in all headers/footers to detect watermark ?

Best Regards,
Arun Chandran C
Software Developer

Hi Arun,


Thanks for your inquiry. We have logged your requirement in our issue tracking system as WORDSNET-12057. Our product team will further look into the details of this problem and we will consider providing appropriate property so that you can detect watermark shape. We will keep you updated on the status of this issue. We apologize for your inconvenience.

Best regards,

Hi Arun,


Thanks for being patient. Regarding WORDSNET-12057, our product team has completed the work on your issue and has come to a conclusion that they will most likely won’t be able to implement the fix to your issue. Your issue (WORDSNET-12057) may be closed with ‘Won’t Fix’ resolution.

In MS Word there is no any special property for watermark. Watermark in MS Word is a simple shape inserted into the header. However, you can identify this shape in order to get/set its properties. You can use Shape.Name to achieve this because when you insert a watermark in MS Word, it sets name of shape like this – “PowerPlusWaterMarkObject357476642”. So if the name of shape contains “WaterMark” substring, you can suppose that this shape is a watermark.

So you can use code like the following to get a watermark shape:

//
Open document.

Document doc = new Document(MyDir + @"watermark.docx");

// Get all shapes form the document.

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);

// Look for watermark shape.

foreach (Shape shape in shapes)

{

if (shape.Name.Contains("WaterMark"))

{

// Here you can access watermark shape properties.

// ..............................................

// For example printe text of the watermark.

Console.WriteLine(shape.TextPath.Text);

}

}


I hope, this helps.

Best regards,

Hi Arun,


Regarding WORDSNET-12057, our product team has completed the work on your issue and has come to a conclusion that they won’t be able to implement the fix to your issue. Your issue (WORDSNET-12057) has now been closed with ‘Won’t Fix’ resolution. Please use the code from my previous post as a workaround.

Best regards,