Aspose.Word NET Watermark image

Hi, How can I use image as watermark with Aspose.Word for .NET? I found example for text watermark, but not image. MSWord 2010 is able to do that, so I beleive it is technically possible.

Thank you


Hi John,


Thanks for your inquiry. Please use the following code example to achieve your requirements. Hope this helps you. Please let us know if you have any
more queries.

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

InsertWatermarkImageAtEachPage(doc, MyDir + "in.jpg");

doc.Save(MyDir + "Out.docx");

public static void InsertWatermarkImageAtEachPage(Document doc, string watermarkImagePath)

{

DocumentBuilder builder = new DocumentBuilder(doc);

PageSetup ps = builder.PageSetup;

NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);

LayoutCollector collector = new LayoutCollector(doc);

Paragraph anchorPara = null;

int pageIndex = 0;

foreach (Paragraph para in paragraphs)

{

if (collector.GetStartPageIndex(para) == pageIndex)

{

anchorPara = para;

Shape watermark = new Shape(doc, Aspose.Words.Drawing.ShapeType.Image);

watermark.ImageData.SetImage(watermarkImagePath);

watermark.Width = 300;

watermark.Height = 300;

watermark.Left = 0;

watermark.Top = 0;

watermark.BehindText = true;

anchorPara.AppendChild(watermark);

pageIndex++;

}

}

}