Cannot remove watermark from 1st page

Hi Support,

We are using aspose-words-17.4.0-jdk16.jar library and trying to remove a watermark. It removes from all other pages except from 1st page. Any clue?
Attached is the java & sample docwatermark.zip (19.4 KB)

Hi there,

Thanks for your inquriy. Please note your document contains a watermark with “136 2050” name instead of “NIAIDDOCXWaterMark”. So you are unable to remove the watermark.

Best Regards,

I was actually looking for both watermark name and watermark text.

if (shape.getName().startsWith(“NIAIDDOCXWaterMark”)
|| shape.getTextPath().getText().equalsIgnoreCase(watermarkText))

If the name didn’t match, then it should able to find the “Draft” text and then remove it, correct?

Thank you

@mpinnamaneni

Thanks for your feedback. If you want to check watermark text then please try following code. It will help you to accomplish the task.

if (shape.getName().startsWith("NIAIDDOCXWaterMark")
|| shape.getText().contains(watermarkText))

Best Regards,

I tried and now it removed only from first page and didn’t remove the watermark from second page.
Thank you

@mpinnamaneni

Thanks for your feedback. We will appreciate it if you please share your sample input document here that contains header footer on both pages, may be you have added different bookmarks to different Header/Footer of document. Please also share your sample code that you are using to add watermark in the problematic document.

Best Regards,

Please notice the beginning of the thread that I already uploaded sample word and also the code. Thank you

@mpinnamaneni

Thanks for your feedback. Please double check the document shared in first post, it has only a single watermark on first page. There is no watermark on second page.

Best Regards,

here you go. Thanks.
sampledoc.zip (22.1 KB)

@mpinnamaneni

Thanks for sharing the source document. We have tested the scenario with shared document and noticed the reported issue. We have logged a ticket WORDSNET-15559 in our issue tracking system for further investigation and rectification. We will notify you as soon as it is resolved.

We are sorry for the inconvenience.

Best Regards,

@mpinnamaneni

Thanks for your patience. We have investigated the issue and found that it is not bug. The shape in header of the first page has empty name, GetText() returns empty string for the both shapes. You should use the TextPath property instead. Please change your code as following:

private static void RemoveWatermarkText(Document doc)
{
    String watermarkText = "Draft";
    foreach (HeaderFooter hf in doc.GetChildNodes(NodeType.HeaderFooter, true))
    {
        Console.WriteLine(hf.HeaderFooterType);
        Console.WriteLine(hf.IsHeader);
        foreach (Shape shape in hf.GetChildNodes(NodeType.Shape, true))
        {
            Console.WriteLine(shape.GetText());
            Console.WriteLine(shape.Name);
            Console.WriteLine(shape.TextPath.Text);
 
            if (shape.Name.Contains("PowerPlusWaterMark") || shape.TextPath.Text.Contains(watermarkText))
            {
                shape.Remove();
            }
        }
    }
}

okay, thank. Will try that option.

Hi Tilal,
I was looking at your last reply and noticed that even I’m using TextPath & Text initially and still its not working. Please refer to my post above. We are using aspose 17.6 version.

@mpinnamaneni

Thanks for your feedback. I have again tested the scenario with following code using both Aspose.Words for Java 17.6 and 17.8 and unable to notice reported issue. Can you please share your sample code and environment details to replicate the issue at our end?AW178.zip (18.3 KB)

Document doc = new Document("1000.01 - Copy.docx");
String watermarkText = "Draft";
for(com.aspose.words.HeaderFooter hf :(Iterable<com.aspose.words.HeaderFooter>) doc.getChildNodes(NodeType.HEADER_FOOTER, true)){
    for(Shape shape :(Iterable<Shape>) hf.getChildNodes(NodeType.SHAPE, true))
    {
    	System.out.println(shape.getText());
    	System.out.println(shape.getName());

        if (shape.getName().startsWith("PowerPlusWaterMark") || shape.getTextPath().getText().contains(watermarkText))
        {
            shape.remove();
        }
    }
}
doc.save("AW178.docx");

I took the same original document attached with this thread and used the same code above and didn’t remove the watermark.
Please find attached code.
Also I’m running this in Eclipse and Windows 7 using ASPOSE 17.6ApplyRemoveWatermark.zip (651 Bytes)

@mpinnamaneni

Thanks for sharing additional information. Please note you have shared two different documents with different Shape names, so you need to update your code accordingly.

If you want to process 1000.01.docx then use following code snippet:

Document doc = new com.aspose.words.Document("1000.01.docx");
.....
if (shape.getName().startsWith("136 2050") || shape.getTextPath().getText().contains(watermarkText))
......

and If you want to process 1000.01 - Copy.docx then use following code snippet:

Document doc = new Document("1000.01 - Copy.docx");
......
if (shape.getName().startsWith("PowerPlusWaterMark") || shape.getTextPath().getText().contains(watermarkText))
......

Hi Tilal,

I wanted to use the text (like Draft) so I don’t have to depend on the shape name as we have hundreds of docs from different old versions and could have different shape names.

Is there any other way?

Thanks,
Mahesh

@mpinnamaneni

Thanks for your feedback. You may try following code, it will help you to accomplish the task.

....
if (shape.getText().contains(watermarkText) || shape.getTextPath().getText().contains(watermarkText)) 
....