Back to Devexpress

WatermarkFormat.SetText(String) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-watermarkformat-dot-settext-x28-system-dot-string-x29.md

latest3.2 KB
Original Source

WatermarkFormat.SetText(String) Method

Replaces watermark text.

Namespace : DevExpress.XtraRichEdit.API.Native

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
void SetText(
    string text
)
vb
Sub SetText(
    text As String
)

Parameters

NameTypeDescription
textString

New watermark text.

|

Remarks

The following code adds a text watermark to the entire document and then changes watermark text in the primary header of the first section:

csharp
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using System.Linq;
// ...

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

// Add a text watermark to the document.
document.WatermarkManager.SetText("DO NOT COPY");

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

// Obtain the section's primary header.
SubDocument headerContent = firstSection.BeginUpdateHeader();
// Retrieve the header's watermark.
var watermark = headerContent.Shapes.SingleOrDefault(x => x.Type == ShapeType.Watermark);
// Change watermark text.
if (watermark != null && watermark.WatermarkFormat.Type == WatermarkType.Text)
{
    watermark.WatermarkFormat.SetText("CONFIDENTIAL");
}
firstSection.EndUpdateHeader(headerContent);
document.SaveDocument(@"Documents\WatermarksUpd.docx", DocumentFormat.Docx);
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
Imports System.Linq
' ...

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

' Add a text watermark to the document.
document.WatermarkManager.SetText("DO NOT COPY")

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

' Obtain the section's primary header.
Dim headerContent As SubDocument = firstSection.BeginUpdateHeader()
' Retrieve the header's watermark.
Dim watermark As Shape = headerContent.Shapes.SingleOrDefault(Function(x) x.Type = ShapeType.Watermark)
' Change watermark text.
If watermark IsNot Nothing AndAlso watermark.WatermarkFormat.Type = WatermarkType.Text Then
    watermark.WatermarkFormat.SetText("CONFIDENTIAL")
End If
firstSection.EndUpdateHeader(headerContent)
document.SaveDocument("Documents\WatermarksUpd.docx", DocumentFormat.Docx)

The following image demonstrates the result:

See Also

WatermarkFormat Interface

WatermarkFormat Members

DevExpress.XtraRichEdit.API.Native Namespace