Add watermarks to word processing documents

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 →

Microsoft Word documents can be divided into multiple sections, and headers and footers are associated with those sections. Open the document with WordProcessingLoadOptions and pass a Word-specific watermark option to add() to target a particular section or page.

Add a watermark to a particular section

Use WordProcessingWatermarkSectionOptions and set section_index to place a watermark in a specific section.

from groupdocs.watermark import Watermarker
from groupdocs.watermark.watermarks import TextWatermark, Font, Color
from groupdocs.watermark.common import HorizontalAlignment, VerticalAlignment
from groupdocs.watermark.options.word_processing import (
    WordProcessingLoadOptions, WordProcessingWatermarkSectionOptions,
)

def add_watermark_to_section():
    with Watermarker("./document.docx", WordProcessingLoadOptions()) as watermarker:
        watermark = TextWatermark("CONFIDENTIAL", Font("Arial", 36.0))
        watermark.foreground_color = Color.red
        watermark.horizontal_alignment = HorizontalAlignment.CENTER
        watermark.vertical_alignment = VerticalAlignment.CENTER
        watermark.rotate_angle = 45.0

        options = WordProcessingWatermarkSectionOptions()
        options.section_index = 0
        watermarker.add(watermark, options)

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

if __name__ == "__main__":
    add_watermark_to_section()

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

Binary file (DOCX, 223 KB)

Download full output

To watermark only specific pages, use WordProcessingWatermarkPagesOptions and set page_numbers.

Working with existing content

Watermarker.get_content() returns a WordProcessingContent that exposes the document’s sections, their shapes, and their headers and footers. For example, to add a watermark to every image inside the first section:

from groupdocs.watermark import Watermarker
from groupdocs.watermark.watermarks import TextWatermark, Font
from groupdocs.watermark.options.word_processing import WordProcessingLoadOptions

with Watermarker("./document.docx", WordProcessingLoadOptions()) as watermarker:
    watermark = TextWatermark("Protected image", Font("Arial", 8.0))
    content = watermarker.get_content()
    for image in content.sections[0].find_images():
        image.add(watermark)
    watermarker.save("./output.docx")

For the full set of Word content operations — shape effects, locking, protection, and working with existing shapes and headers/footers — see the dedicated topics: