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

Free Support Forum - aspose.com

Removing Watermark form document

Hi,

I want to remove a specific watermark present in document. The found following code on aspose forum, which works fine if I don’t put check to compare watermark text.

==============================================================

Document doc = new Document("C:\\watermark.doc");
NodeCollection nodes = doc.getChildNodes(NodeType.SHAPE, true, false);
if (nodes == null || nodes.getCount() < 1)
{
    return;
}
Node[] shapes = nodes.toArray();
int count = shapes.length;
for (int i = 0; i < count; i++)
{

    Shape shape = (Shape)shapes[i];
    String t = shape.getText();
    System.out.println("wwww " + t);
    // if (shape.getText().equalsIgnoreCase("DRAFT"))
    {
        shape.remove();
    }
}
doc.save("C:\\Temp\\out.doc");

==============================================================

Is there any way to compare watermark text. I always get empty text for this shape object.
I am attaching sample file which I am using with this example.

I am using Aspose Word for Java 2.4

Thanks for your help.

Hi
Thanks for your request. In your case watermark is a WordArt shape. You should use TextPath.Text property to get text of this shape. Please try using the following code:

Document doc = new Document("C:\\Temp\\watermark.doc");
NodeCollection nodes = doc.getChildNodes(NodeType.SHAPE, true, false);
if (nodes == null || nodes.getCount() < 1)
{
    return;
}
Node[] shapes = nodes.toArray();
int count = shapes.length;
for (int i = 0; i < count; i++)
{
    Shape shape = (Shape)shapes[i];
    String t = shape.getTextPath().getText();
    System.out.println("wwww " + t);
    if (shape.getTextPath().getText().equalsIgnoreCase("SUN"))
    {
        shape.remove();
    }
}
doc.save("C:\\Temp\\out.doc");

Hope this helps.
Best regards.