Back to Devexpress

ShapeCollection.InsertTextWatermark(DocumentPosition, String) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-shapecollection-dot-inserttextwatermark-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentposition-system-dot-string-x29.md

latest5.6 KB
Original Source

ShapeCollection.InsertTextWatermark(DocumentPosition, String) Method

Inserts a text watermark into the section header.

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
Shape InsertTextWatermark(
    DocumentPosition pos,
    string text
)
vb
Function InsertTextWatermark(
    pos As DocumentPosition,
    text As String
) As Shape

Parameters

NameTypeDescription
posDocumentPosition

The position of the watermark anchor.

| | text | String |

Watermark text.

|

Returns

TypeDescription
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:

csharp
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.Docx);
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
Imports System.Drawing
' ...

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

' Access the first document section.
Dim firstSection As Section = document.Sections(0)

' Obtain the section's primary header.
Dim headerContent As SubDocument = firstSection.BeginUpdateHeader()
' Add a text watermark to the section.
Dim watermark As Shape = 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.Docx)

The following image demonstrates the result:

See Also

ShapeCollection Interface

ShapeCollection Members

DevExpress.XtraRichEdit.API.Native Namespace