Skip to main content
All docs
V24.1

ShapeCollection.InsertTextWatermark(DocumentPosition, String) Method

Inserts a text watermark into the section header.

Namespace: DevExpress.XtraRichEdit.API.Native

Assembly: DevExpress.RichEdit.v24.1.Core.dll

NuGet Packages: DevExpress.RichEdit.Core, DevExpress.Win.Navigation

Declaration

Shape InsertTextWatermark(
    DocumentPosition pos,
    string text
)

Parameters

Name Type Description
pos DocumentPosition

The position of the watermark anchor.

text String

Watermark text.

Returns

Type Description
Shape

The watermark inserted into the header.

Remarks

Watermarks are stored in shape collections (ShapeCollection) of section headers. Call the Section.BeginUpdateHeader method to access a specific section header. Use the header’s SubDocument.Shapes property to return a collection of shapes located in the header. Call the InsertTextWatermark method to add a text watermark to the header. This method displays the watermark in the center of the page.

Note

When you add a watermark to a section header, ensure that the Section.IsHeaderLinkedToPrevious and Section.IsHeaderLinkedToNext methods return false for this header. Otherwise, the header has the same content as the header of the previous or next section, respectively.

You can use properties of the Shape object to change watermark position and customize the watermark’s appearance (modify font attributes and text layout, fill and outline text).

The following example inserts a text watermark into the first document section and adds an outline to watermark text:

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using System.Drawing;
// ...

document.LoadDocument(@"Documents\Watermarks.docx");

// Access the first document section.
Section firstSection = document.Sections[0];

// Obtain the section's primary header.
SubDocument headerContent = firstSection.BeginUpdateHeader();
// Add a text watermark to the section.
Shape watermark = headerContent.Shapes.InsertTextWatermark(headerContent.Range.End, "CONFIDENTIAL");
// Specify text settings.
watermark.WatermarkFormat.TextOptions.FontFamily = "Calibri";
watermark.WatermarkFormat.TextOptions.Color = Color.LightGray;
watermark.WatermarkFormat.TextOptions.Semitransparent = true;
// Add an outline to watermark text.
watermark.Line.Thickness = 2;
watermark.Line.Fill.SetSolidFill(Color.Gray);
firstSection.EndUpdateHeader(headerContent);

document.SaveDocument(@"Documents\WatermarksUpd.docx", DocumentFormat.OpenXml);

The following image demonstrates the result:

Text Watermark

See Also