Aspose words shape is printing behind the image


How to bring the shape above the image in aspose words? Code written in C#.

private static void InsertWaterMarkTextToWord(Aspose.Words.Document doc, string watermarkText)
    // Create a watermark shape. This will be a WordArt shape.
    // You are free to try other shape types as watermarks.
    Shape watermark = new Shape(doc, ShapeType.TextPlainText);

    // Set up the text of the watermark.
    watermark.TextPath.Text = watermarkText;
    watermark.TextPath.FontFamily = "Arial";
    watermark.Width = 500;
    watermark.Height = 80; //100

    // Text will be directed from the bottom-left to the top-right corner.
    watermark.Rotation = -40;
    // Remove the following two lines if you need a solid black text.
    watermark.Fill.Color = System.Drawing.Color.Gray; // Try LightGray to get more Word-style watermark
    watermark.StrokeColor = System.Drawing.Color.Gray; // Try LightGray to get more Word-style watermark

    // Place the watermark in the page center.
    watermark.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
    watermark.RelativeVerticalPosition = RelativeVerticalPosition.Page;
    watermark.WrapType = WrapType.None;
    watermark.VerticalAlignment = Aspose.Words.Drawing.VerticalAlignment.Center;
    watermark.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Center;

    // Create a new paragraph and append the watermark to this paragraph.
    Paragraph watermarkPara = new Paragraph(doc);

    // Insert the watermark into all headers of each document section.
    foreach(Section sect in doc.Sections)
        // There could be up to three different headers in each section, since we want
        // the watermark to appear on all pages, insert into all headers.
        InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderPrimary);
        InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderFirst);
        InsertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HeaderEven);

I have attached the sample file. Please help.

Bhaskar V

Hi Bhaskar,

Thanks for your inquiry. It seems the problem occurs because watermark shape resides inside header footer story and images are inside body story (please see Story class). If you insert a watermark using Microsoft Word 2013 in source document, you will observe the same behaviour. However, could you please attach your input Word document here for testing? We will investigate the scenario on our end and provide you more information.

Best regards,

I have attached input word document. Please check.

Hi Bhaskar,

Thanks for your inquiry. You can overcome this problem by manually inserting watermarks in each Page. You can achieve this by moving the cursor to the first Paragraph in each Page of your document and then making those Paragraphs as an anchor points for your watermarks. Here is how you can achieve this:

public static void InsertWatermarkTextAtEachPage(Document doc, string watermarkText)
    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 = 1;
    foreach(Paragraph para in paragraphs)
        if (collector.GetStartPageIndex(para) == pageIndex && para.GetAncestor(NodeType.GroupShape) == null)
            anchorPara = para;
            Shape watermark = new Shape(doc, Aspose.Words.Drawing.ShapeType.TextPlainText);
            watermark.TextPath.Text = watermarkText;
            watermark.TextPath.FontFamily = "Arial";
            watermark.Width = 300;
            watermark.Height = 70;
            watermark.Left = 100;
            watermark.Top = 100;
            watermark.Rotation = -40;
            watermark.Fill.Color = Color.Gray;
            watermark.StrokeColor = Color.Gray;
            watermark.Name = string.Format("WaterMark_{0}", Guid.NewGuid());
            watermark.WrapType = WrapType.None;

I hope, this helps.

Best regards,