Back to Devexpress

WatermarkManager.SetText(String, TextWatermarkOptions) Method

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

latest5.6 KB
Original Source

WatermarkManager.SetText(String, TextWatermarkOptions) Method

Adds a text watermark to all document pages.

Namespace : DevExpress.XtraRichEdit.API.Native

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
void SetText(
    string text,
    TextWatermarkOptions options
)
vb
Sub SetText(
    text As String,
    options As TextWatermarkOptions
)

Parameters

NameTypeDescription
textString

The watermark text.

| | options | TextWatermarkOptions |

An object that contains text watermark options.

|

Exceptions

TypeDescription
InvalidOperationException

Occurs if the text parameter is null , an empty string, or contains only spaces.

|

Remarks

Watermarks are located in section headers. If a document does not contain headers, a SetText method call adds headers of the Primary type to all document sections.

If the document has multiple sections, this method adds the same watermark to each section and each existing section header (first, primary, odd, or even).

The WatermarkManager.Type property indicates whether the document has watermarks. The property returns WatermarkType.None if the document does not contain watermarks.

Example

The code sample below adds a text watermark to all document pages.

csharp
using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
    wordProcessor.LoadDocument("DocumentProtection.docx");

    TextWatermarkOptions textWatermarkOptions = new TextWatermarkOptions();
    textWatermarkOptions.Color = System.Drawing.Color.LightGray;
    textWatermarkOptions.FontFamily = "Calibri";
    textWatermarkOptions.Layout = WatermarkLayout.Diagonal;
    textWatermarkOptions.Semitransparent = true;

    wordProcessor.Document.WatermarkManager.SetText("CONFIDENTIAL", textWatermarkOptions);
    wordProcessor.SaveDocument("DocumentProtection_new.docx", DocumentFormat.Docx);
}
vb
Using wordProcessor As New RichEditDocumentServer()
    wordProcessor.LoadDocument("DocumentProtection.docx")

    Dim textWatermarkOptions As New TextWatermarkOptions()
    textWatermarkOptions.Color = System.Drawing.Color.LightGray
    textWatermarkOptions.FontFamily = "Calibri"
    textWatermarkOptions.Layout = WatermarkLayout.Diagonal
    textWatermarkOptions.Semitransparent = True

    wordProcessor.Document.WatermarkManager.SetText("CONFIDENTIAL", textWatermarkOptions)
    wordProcessor.SaveDocument("DocumentProtection_new.docx", DocumentFormat.Docx)
End Using

The following code snippets (auto-collected from DevExpress Examples) contain references to the SetText(String, TextWatermarkOptions) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/WatermarkActions.cs#L32

csharp
document.WatermarkManager.SetText("CONFIDENTIAL", textWatermarkOptions);
#endregion #CreateTextWatermark

word-document-api-examples/CS/CodeExamples/WatermarkActions.cs#L41

csharp
// Add a text watermark to all document pages.
document.WatermarkManager.SetText("CONFIDENTIAL", textWatermarkOptions);
#endregion #CreateTextWatermark

word-document-api-examples/VB/CodeExamples/WatermarkActions.vb#L38

vb
' Add a text watermark to all document pages.
            document.WatermarkManager.SetText("CONFIDENTIAL", textWatermarkOptions)
#End Region ' #CreateTextWatermark

See Also

WatermarkManager Interface

WatermarkManager Members

DevExpress.XtraRichEdit.API.Native Namespace