Skip to main content
A newer version of this page is available. .

How to: Add Different Watermarks to Document Pages

  • 2 minutes to read

The following example demonstrates how to specify a unique watermark for different pages in a report. For this you need to call the Page.AssignWatermark method for the page whose watermark needs to be changed, and pass a new watermark to this method as a parameter, as shown below. If you need to remove a watermark from a particular page, pass a new empty watermark to the AssignWatermark method.

using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraPrinting;
using DevExpress.XtraPrinting.Drawing;
// ...

private void button1_Click(object sender, EventArgs e) {
    // Create a report and assign a watermark to it.
    XtraReport1 report = new XtraReport1();
    report.Watermark.CopyFrom(CreateTextWatermark("Common Watermark"));
    report.CreateDocument();

    // Add a custom watermark to the second page.
    Page myPage = report.Pages[1];
    myPage.AssignWatermark(CreateTextWatermark("Second Page"));

    // Remove a watermark from the third page.
    myPage = report.Pages[2];
    myPage.AssignWatermark(new PageWatermark());

    // Show the Print Preview.
    report.ShowPreviewDialog();
}

// Create a watermark with the specified text.
private Watermark CreateTextWatermark(string text) {
    Watermark textWatermark = new Watermark();

    textWatermark.Text = text;
    textWatermark.TextDirection = DirectionMode.ForwardDiagonal;
    textWatermark.Font = new Font(textWatermark.Font.FontFamily, 40);
    textWatermark.ForeColor = Color.DodgerBlue;
    textWatermark.TextTransparency = 150;
    textWatermark.ShowBehind = false;

    return textWatermark;
}

Tip

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E109.

See Also