Hey,
When I try insert watermark to the front of document, in certain pages my watermark looks misaligned…Can you please help me with this?? I have attached the doc file within this…The watermark in Page 22 is misaligned.
I have used following code to bring watermark to the front of document.
NodeCollection smallRuns = sect.GetChildNodes(NodeType.Run, true);
LayoutCollector collector = new LayoutCollector(doc);
int pageIndex = collector.GetStartPageIndex(smallRuns[0]);
foreach (Run run in smallRuns)
{
if (collector.GetStartPageIndex(run) == pageIndex)
{
var watermark = CreateWatermark(watermarkText, doc, false).Clone(true);
builder.MoveTo(run);
builder.CurrentSection.PageSetup.RestartPageNumbering = false;
builder.InsertNode(watermark);
pageIndex++;
}
}
and this for creating watermark
Shape watermark = new Shape(doc, Aspose.Words.Drawing.ShapeType.TextPlainText);
watermark.ZOrder = 2;
// Set up the text of the watermark.
watermark.TextPath.Text = watermarkText;
watermark.TextPath.FontFamily = "Arial";
watermark.Width = 500;
watermark.Height = 100;
// Text will be directed from the bottom-left to the top-right corner.
watermark.AllowOverlap = true;
watermark.Rotation = -40;
// Remove the following two lines if you need a solid black text.
watermark.Fill.Color = System.Drawing.Color.LightGray;
watermark.StrokeColor = System.Drawing.Color.LightGray; // Try LightGray to get more Word-style watermark
watermark.BehindText = behindText;
// 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 = HorizontalAlignment.Center;
// Create a new paragraph and append the watermark to this paragraph.
return watermark;