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 →

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

Add a text watermark

To add a text watermark, follow these steps:

  1. Open the document by passing its path (or a stream) to the Watermarker class, using a with block so the document is released automatically.
  2. Create a TextWatermark with the desired text and Font.
  3. Style the watermark — for example, set foreground_color and alignment.
  4. Call add() to apply the watermark and save() to write the result.
from groupdocs.watermark import Watermarker
from groupdocs.watermark.watermarks import TextWatermark, Font, Color
from groupdocs.watermark.common import HorizontalAlignment, VerticalAlignment

def add_text_watermark():
    with Watermarker("./sample.pdf") as watermarker:
        # Build the text watermark and style it
        watermark = TextWatermark("Top Secret", Font("Arial", 36.0))
        watermark.foreground_color = Color.red
        watermark.horizontal_alignment = HorizontalAlignment.CENTER
        watermark.vertical_alignment = VerticalAlignment.CENTER
        watermark.rotate_angle = 45.0
        watermark.opacity = 0.4

        watermarker.add(watermark)
        watermarker.save("./output.pdf")

if __name__ == "__main__":
    add_text_watermark()

sample.pdf is the sample file used in this example. Click here to download it.

Binary file (PDF, 313 KB)

Download full output

Run the program. A new watermarked document appears at the specified path.

What’s next

GroupDocs.Watermark offers many more capabilities for text watermarks — background and foreground colors, custom fonts, opacity, rotation, tiling, and absolute or relative positioning. See Adding text watermarks in the advanced guide.