We are using the following code to generate a watermark in our document. Unfortunately, the watermark is displayed in back of the other content and as a result looks odd (WatermarkInBack.png (59.9 KB)).
private void InsertWaterMarkText(string waterMarkText)
{
var watermark = new Shape(Document, ShapeType.TextPlainText) { Name = "WaterMark" };
watermark.TextPath.Text = waterMarkText;
watermark.TextPath.FontFamily = "Arial";
watermark.Width = 500;
watermark.Height = 100;
watermark.ZOrder = 100000;
// 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.Red;
watermark.Fill.Opacity = .10;
watermark.StrokeColor = Color.Red;
watermark.Fill.Opacity = .20;
// 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.
var watermarkParagraph = new Paragraph(Document);
watermarkParagraph.AppendChild(watermark);
// Insert the watermark into all headers of each document section.
foreach (var node in Document.Sections)
{
var section = (Section)node;
// 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(watermarkParagraph, section, HeaderFooterType.HeaderPrimary);
InsertWatermarkIntoHeader(watermarkParagraph, section, HeaderFooterType.HeaderFirst);
InsertWatermarkIntoHeader(watermarkParagraph, section, HeaderFooterType.HeaderEven);
}
}
private void InsertWatermarkIntoHeader(Paragraph watermarkParagraph, Section section, HeaderFooterType headerType)
{
var header = section.HeadersFooters[headerType];
if (header == null)
{
header = new HeaderFooter(section.Document, headerType);
section.HeadersFooters.Add(header);
}
header.AppendChild(watermarkParagraph.Clone(true));
}