Back to Devexpress

Watermark Class

corelibraries-devexpress-dot-xtraprinting-dot-drawing.md

latest7.6 KB
Original Source

Watermark Class

A document’s watermark.

Namespace : DevExpress.XtraPrinting.Drawing

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

NuGet Package : DevExpress.Printing.Core

Declaration

csharp
public class Watermark :
    PageWatermark
vb
Public Class Watermark
    Inherits PageWatermark

The following members return Watermark objects:

Remarks

A document can contain either text, or a picture as its watermark. The following properties are in effect for text watermarks only.

The following properties are in effect for picture watermarks only.

Both text and image watermarks have the Watermark.Id property. The unique identifier of a watermark used to specify the watermark in the Page.WatermarkId property.

The Watermark toolbar button and the corresponding menu item are represented via the PrintingSystemCommand.Watermark printing system command. To change the visibility of these items the PrintingSystemBase.SetCommandVisibility method should be used.

The PrintingSystemBase.Watermarks property holds a WatermarkCollection that contains all Watermark objects in the document. To add a watermark to a document, call the Watermark.CopyFrom method or add a watermark to the collection.

When a watermark is specified for a document, it is applied to all pages. To specify individual watermarks for particular pages, use the Page.WatermarkId property or call the Page.AssignWatermark method.

Example

This example demonstrates how to add a watermark to a printing system document. The SetTextWatermark method demonstrates the properties that are used to specify settings when a text watermark is added to a document, while the SetPictureWatermark method demonstrates the properties required to set a picture as a document’s watermark.

csharp
using DevExpress.XtraPrinting;
using DevExpress.XtraPrinting.Drawing;
using DevExpress.Drawing;
// ...

public void SetTextWatermark(PrintingSystem ps){
   // Create the text watermark.
   Watermark textWatermark = new Watermark();

   // Set watermark options.
   textWatermark.Text = "CUSTOM WATERMARK TEXT";
   textWatermark.TextDirection = DirectionMode.ForwardDiagonal;
   textWatermark.Font = new DXFont(textWatermark.Font.FontFamily, 40);
   textWatermark.ForeColor = Color.DodgerBlue;
   textWatermark.TextTransparency = 150;
   textWatermark.TextPosition = WatermarkPosition.InFront;
   textWatermark.PageRange = "1,3-5";

   // Add the watermark to the collection.
   ps.Watermarks.Add(textWatermark);
}

public void SetPictureWatermark(PrintingSystem ps){
   // Create the picture watermark.
   Watermark pictureWatermark = new Watermark();

   // Set watermark options.
   pictureWatermark.Image = Bitmap.FromFile("watermark.gif");
   pictureWatermark.ImageAlignment = ImageAlignment.TopCenter;
   pictureWatermark.ImageTiling = false;
   pictureWatermark.ImageViewMode = ImageViewMode.Stretch;
   pictureWatermark.ImageTransparency = 150;
   pictureWatermark.ImagePosition = WatermarkPosition.Behind;
   pictureWatermark.PageRange = "2,4";

   // Add the watermark to the collection.
   ps.Watermarks.Add(pictureWatermark);
}
vb
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraPrinting.Drawing
Imports DevExpress.Drawing
' ...

Public Sub SetTextWatermark(ByVal ps As PrintingSystem)
   ' Create the text watermark.
   Dim textWatermark As New Watermark()

   ' Set watermark options.
   textWatermark.Text = "CUSTOM WATERMARK TEXT"
   textWatermark.TextDirection = DirectionMode.ForwardDiagonal
   textWatermark.Font = New DXFont(textWatermark.Font.FontFamily, 40)
   textWatermark.ForeColor = Color.DodgerBlue
   textWatermark.TextTransparency = 150
   textWatermark.TextPosition = WatermarkPosition.InFront
   textWatermark.PageRange = "1,3-5"

   ' Add the watermark to the collection.
   ps.Watermarks.Add(textWatermark)
End Sub

Public Sub SetPictureWatermark(ByVal ps As PrintingSystem)
   ' Create the picture watermark.
   Dim pictureWatermark As New Watermark()

   ' Set watermark options.
   pictureWatermark.Image = Bitmap.FromFile("watermark.gif")
   pictureWatermark.ImageAlignment = ImageAlignment.TopCenter
   pictureWatermark.ImageTiling = False
   pictureWatermark.ImageViewMode = ImageViewMode.Stretch
   pictureWatermark.ImageTransparency = 150
   pictureWatermark.ImagePosition = WatermarkPosition.Behind
   pictureWatermark.PageRange = "2,4"

   ' Add the watermark to the collection.
   ps.Watermarks.Add(pictureWatermark)
End Sub

Inheritance

Object DevExpress.Printing.Utils.DocumentStoring.StorableObjectBase PageWatermark Watermark XRWatermark

See Also

Watermark Members

PrintingSystemBase.Watermark

PrintingSystemCommand.Watermark

DevExpress.XtraPrinting.Drawing Namespace