Skip to main content
All docs
V25.1
  • ShapeCollection.InsertImageWatermark(DocumentPosition, Image) Method

    Inserts an image watermark into the section header.

    Namespace: DevExpress.XtraRichEdit.API.Native

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

    NuGet Package: DevExpress.RichEdit.Core

    Declaration

    [Browsable(false)]
    Shape InsertImageWatermark(
        DocumentPosition pos,
        Image image
    )

    Parameters

    Name Type Description
    pos DocumentPosition

    The position of the watermark anchor.

    image Image

    A watermark image.

    Returns

    Type Description
    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:

    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,
        Image.FromFile(@"Images\DevExpressLogo.png"));
    // Remove the washout effect.
    watermark.WatermarkFormat.ImageOptions.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:

    Image Watermark

    See Also