Existing objects in word processing 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 →

Watermarker.get_content() returns a WordProcessingContent whose sections each expose a shapes collection. Watermarks added to a Word document are shapes, so this is how you find, modify, and remove watermarks that already exist in a document.

Extract information about shapes

from groupdocs.watermark import Watermarker
from groupdocs.watermark.options.word_processing import WordProcessingLoadOptions

def extract_shapes():
    with Watermarker("./document.docx", WordProcessingLoadOptions()) as watermarker:
        content = watermarker.get_content()
        for i, section in enumerate(content.sections):
            print(f"Section {i}: shapes={len(section.shapes)}")
            for shape in section.shapes:
                text = (shape.text or "").strip()
                print(f"  shape text={text!r} size={round(shape.width)}x{round(shape.height)} name={shape.name!r}")

if __name__ == "__main__":
    extract_shapes()

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

Section 0: shapes=5
  shape text='' size=100x30 name='Header logo'
  shape text='CONFIDENTIAL' size=440x88 name='WordArt CONFIDENTIAL'
  shape text='' size=300x188 name='Photo: First Roast — Dawn'
  shape text='' size=300x188 name='Photo: Harbour Blue'
  shape text='' size=300x188 name='Photo: Violet Hour'
Section 1: shapes=1
  shape text='' size=360x225 name='Photo: Ember Ridge'
Section 2: shapes=0

Download full output

Each shape exposes text, image, name, alternative_text, x, y, width, height, rotate_angle, is_word_art, and behind_text.

Remove and modify shapes

The shapes collection supports remove_at(index) and remove(shape). Iterate in reverse when removing by index:

from groupdocs.watermark import Watermarker
from groupdocs.watermark.options.word_processing import WordProcessingLoadOptions

def remove_and_modify_shapes():
    with Watermarker("./document.docx", WordProcessingLoadOptions()) as watermarker:
        content = watermarker.get_content()
        for section in content.sections:
            for i in range(len(section.shapes) - 1, -1, -1):
                if section.shapes[i].text == "CONFIDENTIAL":
                    section.shapes.remove_at(i)
        watermarker.save("./output.docx")

if __name__ == "__main__":
    remove_and_modify_shapes()

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

Binary file (DOCX, 222 KB)

Download full output

You can replace a shape’s text by assigning to shape.text, replace its image by assigning a WordProcessingWatermarkableImage to shape.image, set or clear a hyperlink via shape.hyperlink, and modify its position, size, and rotate_angle. Headers and footers are available through section.headers_footers.