Customize watermarks

GroupDocs.Watermark offers many capabilities to customize how the watermark would look and where it will be positioned within the document.

Customizing text watermarks

To adjust a text watermark to your needs, use the properties of the TextWatermark class.

The following options could be set:

OptionDescription
BackgroundColorSpecifies the background color of the text.
ConsiderParentMarginsWhether to take into account the existing page margins of the document when calculating the watermark’s size and coordinates. Default: false.
FontSpecifies the current font of the text watermark.
ForegroundColorSpecifies the foreground color of the text.
HeightSpecifies the desired height of the watermark.
HorizontalAlignmentSpecifies the horizontal alignment of the watermark. Possible values are None (default), Left, Center, and Right.
IsBackgroundWhether to place the watermark below (true) or above (true) the main content. Default: false.
MarginsSpecifies the watermark margins.
OpacityDefines the opacity of the watermark as a value ranging from 0 (fully transparent) to 1 (solid filling).
RotateAngleDefines the rotation angle of the watermark. A positive value corresponds to a clockwise rotation angle, negative - to a counterclockwise rotation angle.
ScaleFactorSpecifies how the watermark size depends on the size of a parent document.
SizingTypeSpecifies a way the watermark should be sized. Possible values are Auto (default), Absolute, ScaleToParentDimensions, and ScaleToParentArea.
TextDefines the text of the watermark.
TextAlignmentSpecifies the alignment of text. Possible values are Left (default), Center, Right, and Justify.
VerticalAlignmentSpecifies the vertical alignment of the watermark. Possible values are None (default), Left, Center, and Bottom.
WidthSpecifies the desired width of the watermark.
XSpecifies the horizontal coordinate of the watermark within the parent document.
YSpecifies the vertical coordinate of the watermark within the parent document.

The code below demonstrates how to specify the desired watermark appearance and position before applying it to the document:

using GroupDocs.Watermark;
using GroupDocs.Watermark.Common;
using GroupDocs.Watermark.Watermarks;

// Specify an absolute or relative path to your document.
using (Watermarker watermarker = new Watermarker("C:\\Docs\\sample.docx"))
{
    // Specify the desired text and font for the watermark
    TextWatermark watermark = new TextWatermark("Customized watermark.", new Font("Arial", 24, FontStyle.Bold));
    // Specify the appearance and the position of the watermark
    watermark.ForegroundColor = Color.DarkOrange;
    watermark.ConsiderParentMargins = true;
    watermark.HorizontalAlignment = HorizontalAlignment.Center;
    watermark.VerticalAlignment = VerticalAlignment.Top;
    watermark.SizingType = SizingType.ScaleToParentDimensions;
    watermark.RotateAngle = 45;
    watermark.ScaleFactor = 0.7;
    // Apply the watermark
    watermarker.Add(watermark);
    // Save the resulting document
    watermarker.Save("C:\\Docs\\watermarked-sample.docx");
}

Run the program. A watermark will be added at a specified position and will have the specified look.

Customized text watermark

Customizing image watermarks

Image watermarks have similar settings that affect their look and position. To adjust an image watermark, use the properties of the ImageWatermark class.

The following options could be set:

OptionDescription
ConsiderParentMarginsWhether to take into account the existing page margins of the document when calculating the watermark’s size and coordinates. Default: false.
HeightSpecifies the desired height of the watermark.
HorizontalAlignmentSpecifies the horizontal alignment of the watermark. Possible values are None (default), Left, Center, and Right.
IsBackgroundWhether to place the watermark below (true) or above (true) the main content. Default: false.
MarginsSpecifies the watermark margins.
OpacityDefines the opacity of the watermark as a value ranging from 0 (fully transparent) to 1 (solid filling).
RotateAngleDefines the rotation angle of the watermark. A positive value corresponds to a clockwise rotation angle, negative - to a counterclockwise rotation angle.
ScaleFactorSpecifies how the watermark size depends on the size of a parent document.
SizingTypeSpecifies a way the watermark should be sized. Possible values are Auto (default), Absolute, ScaleToParentDimensions, and ScaleToParentArea.
VerticalAlignmentSpecifies the vertical alignment of the watermark. Possible values are None (default), Left, Center, and Bottom.
WidthSpecifies the desired width of the watermark.
XSpecifies the horizontal coordinate of the watermark within the parent document.
YSpecifies the vertical coordinate of the watermark within the parent document.

The code below demonstrates how to specify the desired watermark appearance and position before applying it to the document:

using GroupDocs.Watermark;
using GroupDocs.Watermark.Common;
using GroupDocs.Watermark.Watermarks;

// Specify an absolute or relative path to your document.
using (Watermarker watermarker = new Watermarker("C:\\Docs\\seagull.jpg"))
{
    // Specify the desired text and font for the watermark
    ImageWatermark watermark = new ImageWatermark("C:\\Docs\\greetings-stamp.png");
    // Specify watermark position, rotation and opacity
    watermark.HorizontalAlignment = HorizontalAlignment.Right;
    watermark.VerticalAlignment = VerticalAlignment.Top;
    watermark.RotateAngle = 15;
    watermark.IsBackground = false;
    watermark.Opacity = 0.8;
    // Apply the watermark
    watermarker.Add(watermark);
    // Save the resulting document
    watermarker.Save("C:\\Docs\\custom-image-watermark.jpg");
}

Run the program. An image watermark will be added at a specified position.

Customized image watermark