Back to Devexpress

ShapeCollection.InsertImageWatermark(DocumentPosition, DocumentImageSource, ImageWatermarkOptions) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-shapecollection-dot-insertimagewatermark-x28-documentposition-documentimagesource-imagewatermarkoptions-x29.md

latest5.9 KB
Original Source

ShapeCollection.InsertImageWatermark(DocumentPosition, DocumentImageSource, ImageWatermarkOptions) Method

Inserts an image watermark into the section header.

Namespace : DevExpress.XtraRichEdit.API.Native

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
Shape InsertImageWatermark(
    DocumentPosition pos,
    DocumentImageSource image,
    ImageWatermarkOptions watermarkOptions
)
vb
Function InsertImageWatermark(
    pos As DocumentPosition,
    image As DocumentImageSource,
    watermarkOptions As ImageWatermarkOptions
) As Shape

Parameters

NameTypeDescription
posDocumentPosition

The position of the watermark anchor.

| | image | DocumentImageSource |

A watermark image.

| | watermarkOptions | ImageWatermarkOptions |

An object that contains image watermark options.

|

Returns

TypeDescription
Shape

The watermark inserted into the header.

|

Remarks

Watermarks are stored in shape collections (ShapeCollection) of section headers. Call the Section.BeginUpdateHeader method to access a specific section header. Use the header’s SubDocument.Shapes property to return a collection of shapes located in the header. Call the InsertImageWatermark method to add an image watermark to the header. This method displays the watermark in the center of the page.

Note

When you add a watermark to a section header, 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.

You can use properties of the Shape object to change watermark position, rotate the watermark, and change its appearance (modify image settings, add an outline, and so on).

The following example adds an image watermark to the first document section, customizes the watermark’s appearance, and rotates the watermark counterclockwise by 45 degrees:

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

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

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

// Obtain the section's primary header.
var headerContent = firstSection.BeginUpdateHeader();
// Add an image watermark to the section.
Shape watermark = headerContent.Shapes.InsertImageWatermark(headerContent.Range.End,
    DocumentImageSource.FromFile(@"Images\DevExpressLogo.png"),
    new ImageWatermarkOptions() { Washout = false});
// Add a border to the watermark image.
watermark.Line.Thickness = 3;
watermark.Line.Fill.SetSolidFill(Color.Gray);
// Rotate the watermark.
watermark.RotationAngle = -45;
firstSection.EndUpdateHeader(headerContent);

document.SaveDocument(@"Documents\WatermarksUpd.docx", DocumentFormat.Docx);
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
Imports System.Drawing
' ...

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

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

' Obtain the section's primary header.
Dim headerContent As SubDocument = firstSection.BeginUpdateHeader()
' Add an image watermark to the section.
Dim watermark As Shape = headerContent.Shapes.InsertImageWatermark(headerContent.Range.End,
    DocumentImageSource.FromFile("Images\DevExpressLogo.png"),
    New ImageWatermarkOptions() With {.Washout = False})
' Add a border to the watermark image.
watermark.Line.Thickness = 3
watermark.Line.Fill.SetSolidFill(Color.Gray)
' Rotate the watermark.
watermark.RotationAngle = -45
firstSection.EndUpdateHeader(headerContent)

document.SaveDocument("Documents\WatermarksUpd.docx", DocumentFormat.Docx)

The following image demonstrates the result:

See Also

ShapeCollection Interface

ShapeCollection Members

DevExpress.XtraRichEdit.API.Native Namespace