Customize watermarks

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Watermark MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-watermark -- dnx GroupDocs.Watermark.Mcp --yes
Folders, licensing and more →

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 methods of the TextWatermark class and of its base class Watermark.

The following options could be set:

MethodDescription
setBackgroundColorSpecifies the background color of the text.
setConsiderParentMarginsWhether to take into account the existing page margins of the document when calculating the watermark’s size and coordinates. Default: false.
setFontSpecifies the current font of the text watermark.
setForegroundColorSpecifies the foreground color of the text.
setHeightSpecifies the desired height of the watermark.
setHorizontalAlignmentSpecifies the horizontal alignment of the watermark. Takes a HorizontalAlignment constant: None (default), Left, Center, or Right.
setBackgroundWhether to place the watermark below (true) or above (false) the main content. Default: false.
setMarginsSpecifies the watermark margins.
setOpacityDefines the opacity of the watermark as a value ranging from 0 (fully transparent) to 1 (solid filling). Default: 1.
setRotateAngleDefines the rotation angle of the watermark. A positive value corresponds to a clockwise rotation angle, negative - to a counterclockwise rotation angle.
setScaleFactorSpecifies how the watermark size depends on the size of a parent document.
setSizingTypeSpecifies a way the watermark should be sized. Takes a SizingType constant: Auto (default), Absolute, ScaleToParentDimensions, or ScaleToParentArea.
setTextDefines the text of the watermark.
setTextAlignmentSpecifies the alignment of text. Takes a TextAlignment constant: Left (default), Center, Right, or Justify.
setTileOptionsRepeats the watermark across the page. See Adding repeated watermarks.
setVerticalAlignmentSpecifies the vertical alignment of the watermark. Takes a VerticalAlignment constant: None (default), Top, Center, or Bottom.
setWidthSpecifies the desired width of the watermark.
setXSpecifies the horizontal coordinate of the watermark within the parent document.
setYSpecifies 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:

import com.groupdocs.watermark.Watermarker;
import com.groupdocs.watermark.common.HorizontalAlignment;
import com.groupdocs.watermark.common.VerticalAlignment;
import com.groupdocs.watermark.watermarks.Color;
import com.groupdocs.watermark.watermarks.Font;
import com.groupdocs.watermark.watermarks.FontStyle;
import com.groupdocs.watermark.watermarks.SizingType;
import com.groupdocs.watermark.watermarks.TextWatermark;

// Specify an absolute or relative path to your document.
try (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.setForegroundColor(Color.getDarkOrange());
    watermark.setConsiderParentMargins(true);
    watermark.setHorizontalAlignment(HorizontalAlignment.Center);
    watermark.setVerticalAlignment(VerticalAlignment.Top);
    watermark.setSizingType(SizingType.ScaleToParentDimensions);
    watermark.setRotateAngle(45);
    watermark.setScaleFactor(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 methods that the ImageWatermark class inherits from the Watermark class.

The following options could be set:

MethodDescription
setConsiderParentMarginsWhether to take into account the existing page margins of the document when calculating the watermark’s size and coordinates. Default: false.
setHeightSpecifies the desired height of the watermark.
setHorizontalAlignmentSpecifies the horizontal alignment of the watermark. Takes a HorizontalAlignment constant: None (default), Left, Center, or Right.
setBackgroundWhether to place the watermark below (true) or above (false) the main content. Default: false.
setMarginsSpecifies the watermark margins.
setOpacityDefines the opacity of the watermark as a value ranging from 0 (fully transparent) to 1 (solid filling). Default: 1.
setRotateAngleDefines the rotation angle of the watermark. A positive value corresponds to a clockwise rotation angle, negative - to a counterclockwise rotation angle.
setScaleFactorSpecifies how the watermark size depends on the size of a parent document.
setSizingTypeSpecifies a way the watermark should be sized. Takes a SizingType constant: Auto (default), Absolute, ScaleToParentDimensions, or ScaleToParentArea.
setTileOptionsRepeats the watermark across the page. See Adding repeated watermarks.
setVerticalAlignmentSpecifies the vertical alignment of the watermark. Takes a VerticalAlignment constant: None (default), Top, Center, or Bottom.
setWidthSpecifies the desired width of the watermark.
setXSpecifies the horizontal coordinate of the watermark within the parent document.
setYSpecifies 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:

import com.groupdocs.watermark.Watermarker;
import com.groupdocs.watermark.common.HorizontalAlignment;
import com.groupdocs.watermark.common.VerticalAlignment;
import com.groupdocs.watermark.watermarks.ImageWatermark;

// Specify an absolute or relative path to your document
// and to the watermark image.
try (Watermarker watermarker = new Watermarker("C:\\Docs\\seagull.jpg");
     ImageWatermark watermark = new ImageWatermark("C:\\Docs\\greetings-stamp.png")) {
    // Specify watermark position, rotation and opacity
    watermark.setHorizontalAlignment(HorizontalAlignment.Right);
    watermark.setVerticalAlignment(VerticalAlignment.Top);
    watermark.setRotateAngle(15);
    watermark.setBackground(false);
    watermark.setOpacity(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