Back to Devexpress

WatermarkManager.SetImage(Image, ImageWatermarkOptions) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-watermarkmanager-dot-setimage-x28-system-dot-drawing-dot-image-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-imagewatermarkoptions-x29.md

latest5.4 KB
Original Source

WatermarkManager.SetImage(Image, ImageWatermarkOptions) Method

Adds an image watermark to all document pages.

Namespace : DevExpress.XtraRichEdit.API.Native

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
[Browsable(false)]
void SetImage(
    Image image,
    ImageWatermarkOptions options
)
vb
<Browsable(False)>
Sub SetImage(
    image As Image,
    options As ImageWatermarkOptions
)

Parameters

NameTypeDescription
imageImage

A watermark image.

| | options | ImageWatermarkOptions |

An object that contains image watermark options.

|

Remarks

Watermarks are located in section headers. If a document does not contain headers, a SetImage 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 an image watermark to all document pages.

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

    ImageWatermarkOptions imageWatermarkOptions = new ImageWatermarkOptions();
    imageWatermarkOptions.Washout = false;
    imageWatermarkOptions.Scale = 1.5;

    wordProcessor.Document.WatermarkManager.SetImage(Image.FromFile("DevExpress.png"), imageWatermarkOptions);
    wordProcessor.SaveDocument("DocumentProtection_new.docx", DocumentFormat.Docx);
}
vb
Using wordProcessor As New RichEditDocumentServer()
    wordProcessor.LoadDocument("DocumentProtection.docx")

    Dim imageWatermarkOptions As New ImageWatermarkOptions()
    imageWatermarkOptions.Washout = False
    imageWatermarkOptions.Scale = 1.5

    wordProcessor.Document.WatermarkManager.SetImage(Image.FromFile("DevExpress.png"), imageWatermarkOptions)
    wordProcessor.SaveDocument("DocumentProtection_new.docx", DocumentFormat.Docx)
End Using

The following code snippets (auto-collected from DevExpress Examples) contain references to the SetImage(Image, ImageWatermarkOptions) 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#L52

csharp
imageWatermarkOptions.Scale = 2;
document.WatermarkManager.SetImage(System.Drawing.Image.FromFile("Documents//DevExpress.png"), imageWatermarkOptions);
#endregion #CreateImageWatermark

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

csharp
// Add an image watermark to all document pages.
wordProcessor.Document.WatermarkManager.SetImage(Image.FromFile("Documents//DevExpress.png"), imageWatermarkOptions);
#endregion #CreateImageWatermark

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

vb
' Add an image watermark to all document pages.
            wordProcessor.Document.WatermarkManager.SetImage(System.Drawing.Image.FromFile("Documents//DevExpress.png"), imageWatermarkOptions)
#End Region ' #CreateImageWatermark

See Also

WatermarkManager Interface

WatermarkManager Members

DevExpress.XtraRichEdit.API.Native Namespace