Adding watermark to images inside a 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 →

Beyond watermarking a document’s pages, you can watermark the images embedded inside it. Watermarker.get_images() returns a collection of every raster image in the document, regardless of format, and each image accepts its own watermark via add().

Watermark every embedded image

The example finds all embedded images, watermarks the larger ones (over 100×100), and saves the result.

from groupdocs.watermark import Watermarker
from groupdocs.watermark.watermarks import TextWatermark, Font, Color, SizingType
from groupdocs.watermark.options.pdf import PdfLoadOptions

def watermark_images_inside():
    with Watermarker("./document.pdf", PdfLoadOptions()) as watermarker:
        watermark = TextWatermark("PROTECTED", Font("Arial", 8.0))
        watermark.foreground_color = Color.red
        watermark.sizing_type = SizingType.SCALE_TO_PARENT_DIMENSIONS
        watermark.scale_factor = 1.0

        # Every raster image embedded in the document
        for image in watermarker.get_images():
            # Skip tiny images such as icons or bullets
            if image.width > 100 and image.height > 100:
                image.add(watermark)

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

if __name__ == "__main__":
    watermark_images_inside()

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

Binary file (PDF, 930 KB)

Download full output

For the example document (10 embedded images), 8 images larger than 100×100 are watermarked. get_images() works the same way for Word, Excel, PowerPoint, and other formats — open the document and iterate the returned collection. You can also pass an ImageWatermark to image.add(...) to stamp a logo onto each embedded image.