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

Free Support Forum - aspose.com

Water mark is coming behind text

Hi,

In our application we add watermarks to documents. In all documents watermark is coming properly but in only one documet it is coming behind the text.

The code which we are using for adding water mark is

public static void AddWatermark(Aspose.Words.Document doc, string WatermarkText)

{

Aspose.Words.Drawing.

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

// Set up the text of the watermark.

watermark.TextPath.Text = WatermarkText;

watermark.TextPath.FontFamily =

"Times New Roman";

watermark.TextPath.Size = 10;

watermark.Width =

ConvertUtil.InchToPoint(2.82);

watermark.Height =

ConvertUtil.InchToPoint(1.41);

// 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 =

Color.Gray; // Try LightGray to get more Word-style watermark

watermark.StrokeColor =

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 =

VerticalAlignment.Center;

watermark.HorizontalAlignment = Aspose.Words.Drawing.

HorizontalAlignment.Center;

// Create a new paragraph and append the watermark to this paragraph.

Aspose.Words.

Paragraph watermarkPara = new Aspose.Words.Paragraph(doc);

watermarkPara.AppendChild(watermark);

watermark.Name =

string.Format("WaterMark_{0}", Guid.NewGuid());

// Insert the watermark into all headers of each document section.

foreach (Aspose.Words.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 attatched the sample document for you reference.

Kindly tell me how can i make watermark to come in such a way that both water mark and text are visible.

Hi,


Thanks for your inquiry. The problem occurs because white background pattern color is specified as Shading to the problematic Paragraph. You can fix this issue by using the following code:

Document doc = new
Document(MyDir + @“sample+document.doc”);

doc.FirstSection.Body.Paragraphs[10].ParagraphFormat.Shading.BackgroundPatternColor = Color.Empty;

doc.Save(MyDir + @“out.doc”);


I hope, this helps.

Best regards,