Watermarks in PDF document

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 →

A PDF watermark can be added in three different ways, each with its own trade-offs:

  • XObjects — added to the real page content. They are not removed by simple sanitization, which makes them the hardest to remove.
  • Artifacts — added as page artifacts. Use PdfArtifactWatermarkOptions.
  • Annotations — added as page annotations. Use PdfAnnotationWatermarkOptions; these can be made print-only so they appear when the document is printed but are hidden on screen.

Add artifact and annotation watermarks

The example below adds an artifact text watermark, an annotation text watermark, and a print-only annotation image watermark.

from groupdocs.watermark import Watermarker
from groupdocs.watermark.watermarks import TextWatermark, ImageWatermark, Font
from groupdocs.watermark.common import HorizontalAlignment, VerticalAlignment
from groupdocs.watermark.options.pdf import (
    PdfLoadOptions, PdfArtifactWatermarkOptions, PdfAnnotationWatermarkOptions,
)

def add_pdf_watermarks():
    with Watermarker("./document.pdf", PdfLoadOptions()) as watermarker:
        # Add as an artifact
        artifact_text = TextWatermark("Artifact", Font("Arial", 8.0))
        artifact_text.horizontal_alignment = HorizontalAlignment.RIGHT
        watermarker.add(artifact_text, PdfArtifactWatermarkOptions())

        # Add as an annotation
        annotation_text = TextWatermark("Annotation", Font("Arial", 8.0))
        annotation_text.horizontal_alignment = HorizontalAlignment.LEFT
        annotation_text.vertical_alignment = VerticalAlignment.TOP
        watermarker.add(annotation_text, PdfAnnotationWatermarkOptions())

        # Add a print-only annotation (visible when printed, hidden on screen)
        with ImageWatermark("./logo.png") as image_watermark:
            image_watermark.horizontal_alignment = HorizontalAlignment.RIGHT
            image_watermark.vertical_alignment = VerticalAlignment.TOP
            options = PdfAnnotationWatermarkOptions()
            options.print_only = True
            watermarker.add(image_watermark, options)

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

if __name__ == "__main__":
    add_pdf_watermarks()

document.pdf and logo.png are the sample files used in this example. Download document.pdf and logo.png.

Binary file (PDF, 1.0 MB)

Download full output

To work with watermarks already present in a PDF — extracting, modifying, or removing existing XObjects, artifacts, and annotations — see Existing objects in PDF document.