How to insert WaterMark?

Hi ,
I need to add Watermark to Document through Aspose . Is it possible ? Can u help me?

Hi

Thanks for your inquiry. Yes of course you can insert Watermark in the document using Aspose.Words. Please follow the link to learn how to achieve this:
https://docs.aspose.com/words/net/working-with-watermark/

Best regards,

Thanks for ur reply.While importing doc (containing Watermark) through Aspose is it possible to identify watermark ?? .In case of Sequence Field ,we can able to identify it by code of ’ FIELD.SEQUENCE '.Like tat is it possible to identify watermark ??

While importing ,I need to get watermark text from doc through Aspose .

please do help me .

Hi

Thanks for your inquiry. MS Word adds Watermarks in the document as WordArt Shape with name like this “PowerPlusWaterMarkObject357766095”. So you can use shape name to identify Watermarks in Word documents. I think information provided in the following thread could be useful for you:
https://forum.aspose.com/t/87687

Hope this helps.

Best regards,

Thanks for ur prompt response. it worked well .but i need to get Watermark text, provided by user .for example see this attached doc .it has watermark named ‘Ramakrishnan’.i need to get tat name .

Thanks in advance ,

Thanks for your inquiry. I think, you can try using code like the following:

Document doc = new Document(@"Test010\Watermark.doc");
NodeCollection shapesColl = doc.GetChildNodes(NodeType.Shape, true, false);
foreach(Shape shape in shapesColl)
{
    // Idetntify shape as watermark.
    if (shape.Name.Contains("WaterMark"))
        // Get text of the watermark.
        Console.WriteLine(shape.TextPath.Text);
}

Hope this helps.
Best regards,

Thanks for ur response . im using java .I cant find Name,TextPath.text function under SHAPE class. Can u give me the java code ?

Thanks in advance

Here is the same code in Java.

Document doc = new Document("C:\\Temp\\Watermark.doc");
NodeCollection shapesColl = doc.getChildNodes(NodeType.SHAPE, true, false);
for (int i = 0; i <shapesColl.getCount(); i++)
{
    Shape shape = (Shape) shapesColl.get(i);
    // Idetntify shape as watermark.
    if (shape.getName().contains("WaterMark"))
        // Get text of the watermark.
        System.out.println(shape.getTextPath().getText());
}

Also, please see Aspose.Words for java API reference:
https://reference.aspose.com/words/java/com.aspose.words/shapebase/#getName
Best regards,

HI
I inserted a watermark into document through aspose .When i open that document in Microsoft Word , i can see watermark ,but if i again insert watermark to that document in word ,I am getting two watermarks .Here is my code .

public class watermark
{
    public static void main(String[] args) throws Exception
    {
        Document doc = new Document("ordinary.doc");
        insertWatermarkText(doc, "CONFIDENTIAL");
        doc.save("WaterMark.doc");
    }
    private static void insertWatermarkText(Document doc, String watermarkText) throws Exception
    {
        Shape watermark = new Shape(doc, ShapeType.TEXT_PLAIN_TEXT);
        DocumentBuilder builder = new DocumentBuilder();
        watermark.getTextPath().setText(watermarkText);
        watermark.setWrapType(WrapType.NONE);
        watermark.setBehindText(true);
        watermark.setWidth(500);
        watermark.setHeight(100);
        watermark.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
        watermark.setHorizontalAlignment(HorizontalAlignment.CENTER);
        watermark.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
        watermark.setVerticalAlignment(VerticalAlignment.CENTER);
        watermark.getTextPath().setFontFamily("Arial");
        watermark.setRotation(-45);
        watermark.getFill().setColor(Color.RED);
        watermark.setStrokeColor(Color.RED);
        watermark.setWrapType(WrapType.NONE);
        Paragraph watermarkPara = new Paragraph(doc);
        watermarkPara.appendChild(watermark);
        for (Section sect: doc.getSections())
        {
            insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_PRIMARY);
            insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_FIRST);
            insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_EVEN);
        }
    }
    private static void insertWatermarkIntoHeader(Paragraph watermarkPara, Section sect, int headerType) throws Exception
    {
        HeaderFooter header = sect.getHeadersFooters().getByHeaderFooterType(headerType);
        if (header == null)
        {
            header = new HeaderFooter(sect.getDocument(), headerType);
            sect.getHeadersFooters().add(header);
        }
        header.appendChild(watermarkPara.deepClone(true));
    }
}

am i doing anything wrong ??
Please do help me.

Hi

Thanks for your inquiry. MS Word identifies watermarks by shape names. So, you can just specify name of shape, like MS Word does. For example:

watermark.setName("PowerPlusWaterMarkObject357476642");

Hope this helps.
Best regards,