Back to Devexpress

WatermarkManager.SetText(Section, HeaderFooterType, String, TextWatermarkOptions) Method

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

latest7.8 KB
Original Source

WatermarkManager.SetText(Section, HeaderFooterType, String, TextWatermarkOptions) Method

Adds a text watermark to a header of the specified section.

Namespace : DevExpress.XtraRichEdit.API.Native

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
void SetText(
    Section section,
    HeaderFooterType type,
    string text,
    TextWatermarkOptions options
)
vb
Sub SetText(
    section As Section,
    type As HeaderFooterType,
    text As String,
    options As TextWatermarkOptions
)

Parameters

NameTypeDescription
sectionSection

The target section.

| | type | HeaderFooterType |

The type of the section’s header in which to insert the watermark.

| | text | String |

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

If you need to add a watermark to a header of a specific section, 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.

If a section defined by the section parameter does not have a header of the specified type, the SetText method creates this header. Consider the following when you use this method to create a header and insert a watermark:

The code sample below adds different watermarks to the document sections. The document contains two sections: the first section occupies the first page, and the second section occupies the second page. All sections have no headers. The WatermarkManager.SetImage method creates the first page header for the first section and adds an image watermark to this header. The WatermarkManager.SetText method creates a primary header (the same header for all pages) for the second section and inserts a text watermark into this header.

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

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

var firstSection = document.Sections[0];
var secondSection = document.Sections[1];

// Define image watermark options.
var imageWatermarkOptions = new ImageWatermarkOptions
{ Washout = false };

// Add an image watermark to the first page header. 
firstSection.DifferentFirstPage = true;
document.WatermarkManager.SetImage(firstSection, HeaderFooterType.First, 
    Image.FromFile(@"Images\DevExpressLogo.png"), imageWatermarkOptions);

// Define text watermark options.
var textWatermarkOptions = new TextWatermarkOptions
{
    Color = System.Drawing.Color.LightGray,
    FontFamily = "Calibri",
    Layout = WatermarkLayout.Horizontal,
    Semitransparent = false
};

// Add a text watermark to the second section's header.
document.WatermarkManager.SetText(secondSection, HeaderFooterType.Primary, "DRAFT", textWatermarkOptions);
document.SaveDocument(@"Documents\WatermarksUpd.docx", DocumentFormat.Docx);
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
Imports System.Drawing
' ...

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

Dim firstSection As Section = document.Sections(0)
Dim secondSection As Section = document.Sections(1)

' Define image watermark options.
Dim imageWatermarkOptions As New ImageWatermarkOptions With {.Washout = False}

' Add an image watermark to the first page header. 
firstSection.DifferentFirstPage = True
document.WatermarkManager.SetImage(firstSection, HeaderFooterType.First, 
    Image.FromFile("Images\DevExpressLogo.png"), imageWatermarkOptions)

' Define text watermark options.
Dim textWatermarkOptions As New TextWatermarkOptions With {
    .Color = System.Drawing.Color.LightGray,
    .FontFamily = "Calibri",
    .Layout = WatermarkLayout.Horizontal,
    .Semitransparent = False
}

' Add a text watermark to the second section's header.
document.WatermarkManager.SetText(secondSection, HeaderFooterType.Primary, "DRAFT", textWatermarkOptions)
document.SaveDocument("Documents\WatermarksUpd.docx", DocumentFormat.Docx)

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SetText(Section, HeaderFooterType, 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.

how-to-add-a-watermark-to-the-document/CS/Form1.cs#L27

csharp
};
    richEditControl1.Document.WatermarkManager.SetText(section, HeaderFooterType.Primary, "DevExpress XtraRichEdit", options);
}

how-to-add-a-watermark-to-the-document/VB/Form1.vb#L28

vb
}
    richEditControl1.Document.WatermarkManager.SetText(section, HeaderFooterType.Primary, "DevExpress XtraRichEdit", options)
End Sub

See Also

WatermarkManager Interface

WatermarkManager Members

DevExpress.XtraRichEdit.API.Native Namespace