officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-watermarkformat-dot-setimage-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentimagesource-x29.md
Replaces the watermark image.
Namespace : DevExpress.XtraRichEdit.API.Native
Assembly : DevExpress.RichEdit.v25.2.Core.dll
NuGet Package : DevExpress.RichEdit.Core
void SetImage(
DocumentImageSource imageSource
)
Sub SetImage(
imageSource As DocumentImageSource
)
| Name | Type | Description |
|---|---|---|
| imageSource | DocumentImageSource |
A new watermark image.
|
The following code adds an image watermark to the entire document and then changes the image for the watermark located in the primary header of the first section:
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using System.Drawing;
using System.Linq;
// ...
document.LoadDocument(@"Documents\Watermarks.docx");
// Add an image watermark to the document.
document.WatermarkManager.SetImage(DocumentImageSource.FromFile(@"Images\DevExpressLogo.png"));
// 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 the watermark image.
if (watermark != null && watermark.WatermarkFormat.Type == WatermarkType.Image)
{
watermark.WatermarkFormat.SetImage(Image.FromFile(@"Images\DevAVLogo.png"));
}
firstSection.EndUpdateHeader(headerContent);
document.SaveDocument(@"Documents\WatermarksUpd.docx", DocumentFormat.Docx);
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
Imports System.Drawing
Imports System.Linq
' ...
document.LoadDocument("Documents\Watermarks.docx")
' Add an image watermark to the document.
document.WatermarkManager.SetImage(DocumentImageSource.FromFile("Images\DevExpressLogo.png"))
' 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 the watermark image.
If watermark IsNot Nothing AndAlso watermark.WatermarkFormat.Type = WatermarkType.Image Then
watermark.WatermarkFormat.SetImage(Image.FromFile("Images\DevAVLogo.png"))
End If
firstSection.EndUpdateHeader(headerContent)
document.SaveDocument("Documents\WatermarksUpd.docx", DocumentFormat.Docx)
See Also