Skip to main content

Display Watermarks in a Report

  • 7 minutes to read

DevExpress Reporting allows you to display text and picture watermarks on report pages. You can also specify an expression that assigns different watermarks to pages.

This tutorial includes information about the following tasks:

  • How to add watermarks.

  • How to specify watermark settings.

  • How to manage watermarks at runtime.

  • How to use pre-printed forms.

add-a-watermark-to-a-report-6

Add a Watermark to the Watermark Collection in the UI

Click the report’s smart tag. Click the Watermark property’s ellipsis button.

add-a-watermark-to-a-report-0

In the invoked Watermark collection editor, select the Text Settings tab to add a text watermark, or the Picture Settings tab to add a picture watermark.

Specify Text Watermark Settings

Specify the following settings:

add-a-watermark-to-a-report-1

Text
The watermark’s text.
Direction
The incline of the watermark’s text.
Font
The font of the watermark’s text.
Color
The foreground color of the watermark’s text.
Size
The size of the watermark’s text.
Bold
Formats the watermark’s text as bold.
Italic
Formats the watermark’s text as italic.
Position
Specifies whether a watermark should be printed behind or in front of page content.
Transparency
The transparency of the watermark’s text.
Id
The unique identifier of a watermark used to specify the watermark in the WatermarkId property (See the Manage Watermark Collection section for details).
Page Range
The range of pages which contain a watermark.

Click OK to add a watermark to the watermark collection. The added watermark is automatically displayed in the report in Preview mode.

add-a-watermark-to-a-report-6

Note

A report can display only one watermark on a report page.

Specify Picture Watermark Settings

Specify an image. Click the Load image option’s Browse button.

add-a-watermark-to-a-report-2

In the invoked Select Picture dialog, select the file that contains the watermark image and click Open.

add-a-watermark-to-a-report-3

Specify the following picture options:

Watermark settings

Size Mode
The mode in which a picture watermark is displayed.
Tiling
Specifies whether a picture watermark should be tiled.
Horizontal Alignment
Specifies the horizontal alignment of the watermark.
Vertical Alignment
Specifies the vertical alignment of the watermark.
Position
Specifies whether a watermark should be printed behind or in front of page content.
Transparency
The transparency of the watermark’s image.
Id
The unique identifier of a watermark used to specify the watermark in the WatermarkId property (See the Manage Watermark Collection section for details).
Page Range
The range of pages which contain a watermark.

Note

The Transparency property is unavailable when users specify an SVG image.

Click OK to add a watermark to the watermark collection. The added watermark is automatically displayed in the report in Preview mode.

The watermark collection

Note

A report can display only one watermark on a report page.

Use Preprinted Forms

You can show a picture watermark on the report’s body at design time as a preprinted form template.

The image below demonstrates a preprinted form template.

add-a-watermark-to-a-report-5

Add a template image to a report as a watermark image. Set the report’s XtraReport.DrawWatermark property to True in the Properties window.

add-a-watermark-to-a-report-4

add-a-watermark-to-a-report-5

Place report controls on the report’s body according to the preprinted form layout.

add-a-watermark-to-a-report-5a

Supported Image Formats

A picture watermark supports the following formats:

  • BMP
  • JPG / JPEG / JPE / JFIF
  • GIF
  • TIF / TIFF
  • PNG
  • ICO
  • DIB
  • RLE
  • EMF / WMF
  • SVG

Combine Text and a Picture in One Watermark

You can display both text and a picture in one Watermark. Use the PageWatermark.TextPosition and PageWatermark.ImagePosition properties of the watermark to specify whether the text and picture should be displayed behind or in front of page content.

For example, create a watermark and specify its text and picture settings.

Set position of the text to In front:

Position In front

Set position of the picture to Behind:

Position Behind

As a result, the image is displayed behind the table, while the text is in front of the content:

Display text and image watermarks in one page

Add a Watermark to the Watermark Collection in Code

The XtraReport.Watermarks property holds a WatermarkCollection that contains all Watermark objects in the report.

This example demonstrates how to add a watermark to a report. The SetTextWatermark method demonstrates the properties you can use to add a text watermark to a report; the SetPictureWatermark method demonstrates properties required to set a picture as the report’s watermark.

using System.Drawing;
using DevExpress.XtraPrinting;
using DevExpress.XtraPrinting.Drawing;
using DevExpress.Drawing;
// ...
public void SetTextWatermark(XtraReport report) {
    // Create a new watermark.
    Watermark textWatermark = new Watermark();
    // Specify watermark settings.
    textWatermark.Text = "CUSTOM WATERMARK TEXT";
    textWatermark.TextDirection = DirectionMode.ForwardDiagonal;
    textWatermark.Font = new DXFont(textWatermark.Font.Name, 40);
    textWatermark.ForeColor = Color.DodgerBlue;
    textWatermark.TextTransparency = 150;
    textWatermark.TextPosition = WatermarkPosition.InFront;
    textWatermark.PageRange = "1,3-5";
    textWatermark.Id = "Watermark1";
    // Add the watermark to the collection.
    report.Watermarks.Add(textWatermark);
}
public void SetPictureWatermark(XtraReport report) {
    Watermark pictureWatermark = new Watermark();
    pictureWatermark.ImageSource = ImageSource.FromFile("Watermark.png");
    pictureWatermark.ImageAlign = ContentAlignment.TopCenter;
    pictureWatermark.ImageTiling = false;
    pictureWatermark.ImageViewMode = ImageViewMode.Stretch;
    pictureWatermark.ImageTransparency = 150;
    pictureWatermark.ImagePosition = WatermarkPosition.Behind;
    pictureWatermark.PageRange = "2,4";
    pictureWatermark.Id = "Watermark2";
    report.Watermarks.Add(pictureWatermark);
}

Manage the Watermark Collection

Display a Specific Watermark in a Report

WatermarkId allows you to specify a watermark from the collection to display in the report. This property has a priority over the watermark’s PageRange property.

Design-Time

Create two watermarks in the Watermarks collection editor.

Create two watermarks

Set WatermarkId to Watermark2 (the Watermark.Id property value).

Display the second watermark in the collection

The image below shows the result.

Display specific watermark

Runtime

The following code snippet adds two watermarks in WatermarkCollection and displays the second watermark in a report:

using DevExpress.Drawing;
using DevExpress.XtraPrinting.Drawing;
using DevExpress.XtraReports.UI;
// ...
XtraReportCategories report = new XtraReportCategories();
  report.Watermarks.Add(CreateTextWatermark("First Watermark","Watermark1"));
  report.Watermarks.Add(CreateTextWatermark("Second Watermark", "Watermark2"));
  report.WatermarkId = "Watermark2";
  report.ShowRibbonPreviewDialog();
  // ...

private Watermark CreateTextWatermark(string text, string id) {
Watermark textWatermark = new Watermark();
textWatermark.Text = text;
textWatermark.Id = id; 
textWatermark.TextDirection = DirectionMode.ForwardDiagonal;
textWatermark.Font = new DXFont("Verdana", 36);
textWatermark.TextPosition = WatermarkPosition.InFront;
textWatermark.ForeColor = Color.Red;
return textWatermark;
}

You can also call the Page.AssignWatermark method to specify a unique watermark for different pages in a report. Page.AssignWatermark takes priority over WatermarkId.

Display Watermarks According to the Specified Condition

Bind WatermarkId to an expression to apply watermarks stored in the collection to specific report pages.

Design-Time

Create the “First page watermark”, “Even page watermark”, and “Odd page watermark” watermarks with the following settings:

Create three watermarks

Specify the expression in the report’s WatermarkId property:

Iif([Arguments.PageIndex]=0,'Watermark_0',Iif([Arguments.PageIndex]%2=0,'Watermark_1','Watermark_2'))

Specify the expression

The image below shows the result.

Display different watermarks

Runtime

The following code snippet adds different watermarks to the first, odd, and even pages of XtraReport:

using DevExpress.XtraReports.UI;
// ...
public partial class XtraReport : DevExpress.XtraReports.UI.XtraReport {
   private void XtraReport_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e){
            XtraReport report = new XtraReport();
            ExpressionBinding watermarksBinding = new ExpressionBinding();
            watermarksBinding.EventName = nameof(BeforePrint);
            // Specify an expression that is rendered within the BeforePrint event.
            watermarksBinding.Expression = "`Iif([Arguments.PageIndex]=0,'Watermark_0',Iif([Arguments.PageIndex]%2=0,'Watermark_1','Watermark_2'))`";
            watermarksBinding.PropertyName = nameof(WatermarkId);
            report.ExpressionBindings.Add(watermarksBinding);
    }
}

Review the following help topic for more information on how to bind expressions to report elements: Data Binding Modes.

Troubleshooting

Merged Reports

If the main report does not have a watermark, the resulting merged report does not have a watermark either. To solve this problem, add a watermark to individual report pages using the Page.AssignWatermark method.