Add text 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 →

On this page

One of the main features of the GroupDocs.Watermark library is adding text watermarks to documents. You may add watermarks to documents or images from local disks, as well as from streams. For a full list of supported document formats, check Supported formats.

To add a text watermark perform the following steps:

  1. Create an instance of the Watermarker class for a local file or file stream;
  2. Create an instance of the TextWatermark class and specify the desired text and font for the watermark;
  3. (Optionally.) Specify the watermark color, horizontal and vertical alignments;
  4. Call the add method to apply the watermark to the document;
  5. Call the save method to store the document in a new location.
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.TextWatermark;

// Specify an absolute or relative path to your document.
try (Watermarker watermarker = new Watermarker("C:\\Docs\\contract.docx")) {
    // Specify the desired text and font for the watermark
    TextWatermark watermark = new TextWatermark("Contract Draft",
            new Font("Arial", 60, FontStyle.Bold));
    // Specify font color, text opacity and alignments
    watermark.setForegroundColor(Color.getDarkGreen());
    watermark.setOpacity(0.5);
    watermark.setHorizontalAlignment(HorizontalAlignment.Center);
    watermark.setVerticalAlignment(VerticalAlignment.Center);
    // Apply the watermark
    watermarker.add(watermark);
    // Save the resulting document
    watermarker.save("C:\\Docs\\watermarked-contract.docx");
}

Run the program. A new watermarked document will appear in the specified path.

Adding text watermarks

What’s next

GroupDocs.Watermark offers many more capabilities for adding text watermarks. For example, it allows specifying background and foreground colors, formatting, text opacity, use of absolute or relative positioning, custom fonts, and so on. To learn more about this, see the Adding text watermarks article of the “Advanced usage” section.

On this page