---
title: "Working with Watermark in Python"
---

```
*Purpose Summary. What is this page about?*

This page demonstrates how to use Aspose.Words for Python via .NET to add, customize, and remove text or image watermarks in Word documents. It includes code examples for inserting watermarks via the Watermark class, using shapes, and handling watermarks inside table cells.
```

This topic discusses how to work programmatically with watermark using Aspose.Words. A watermark is a background image that displays behind the text in a document. A watermark can contain a text or an image represented by the [Watermark](https://reference.aspose.com/words/python-net/aspose.words/watermark/) class.

```

**Try online**

You can try this functionality with our [Free online document watermark](https://products.aspose.app/words/watermark).

```

## How to Add a Watermark to a Document

In Microsoft Word, a watermark can easily be inserted in a document using the Insert Watermark command. Aspose.Words provides the [Watermark](https://reference.aspose.com/words/python-net/aspose.words/watermark/) class to add or remove watermark in documents. Aspose.Words provides the [WatermarkType](https://reference.aspose.com/words/python-net/aspose.words/watermarktype/) enumeration defining three possible types of watermarks ([TEXT](https://reference.aspose.com/words/python-net/aspose.words/watermarktype/#text), [IMAGE](https://reference.aspose.com/words/python-net/aspose.words/watermarktype/#image), and [NONE](https://reference.aspose.com/words/python-net/aspose.words/watermarktype/#none)) to work with. 

### Add Text Watermark

The following code example demonstrates how to insert a text watermark in a document by defining [TextWatermarkOptions](https://reference.aspose.com/words/python-net/aspose.words/textwatermarkoptions/) using the [set_text](https://reference.aspose.com/words/python-net/aspose.words/watermark/set_text/) method:

{{< gist "aspose-words-gists" "e9d8f984dac599756ccb4a64b8c79768" "Examples-DocsExamples-DocsExamples-Programming with Documents-Working with Graphic Elements-working_with_watermark-AddTextWatermarkWithSpecificOptions.py" >}}

### Add Image Watermark

The following code example demonstrates how to insert an image watermark in a document by defining [ImageWatermarkOptions](https://reference.aspose.com/words/python-net/aspose.words/imagewatermarkoptions/) using the [set_image](https://reference.aspose.com/words/python-net/aspose.words/watermark/set_image/) method:

{{< gist "aspose-words-gists" "e9d8f984dac599756ccb4a64b8c79768" "Examples-DocsExamples-DocsExamples-Programming with Documents-Working with Graphic Elements-working_with_watermark-AddImageWatermarkWithSpecificOptions.py" >}}

Image watermark can be inserted as image, string, or stream.

The watermark can also be inserted using shape class as well. It is very easy to insert any shape or image into a header or footer and thus create a watermark of any imaginable type.

The following code example inserts a watermark into a Word document:

{{< gist "aspose-words-gists" "e9d8f984dac599756ccb4a64b8c79768" "Examples-DocsExamples-DocsExamples-Programming with Documents-Working with Graphic Elements-working_with_watermark-AddWatermark.py" >}}

```

You can download the template file of this example from [here](https://github.com/aspose-words/Aspose.Words-for-Python-via-.NET/blob/master/Examples/Data/Document.docx). 

```

## Remove Watermark from a Document

The [Watermark](https://reference.aspose.com/words/python-net/aspose.words/watermark/) class provides the remove method to remove the watermark from a document.

The following code example shows how to remove a watermark from documents:

{{< gist "aspose-words-gists" "e9d8f984dac599756ccb4a64b8c79768" "Examples-DocsExamples-DocsExamples-Programming with Documents-Working with Graphic Elements-working_with_watermark-RemoveWatermarkFromDocument.py" >}}

If the watermarks are added using the [Shape](https://reference.aspose.com/words/python-net/aspose.words.drawing/shape/) class object then to remove the watermark from a document you have to set only the name of watermark shape during inserting and then remove watermark shape by an assigned name.

The following code example show you how to set the name of the watermark shape and remove it from the document:

```python
# Set name to be able to remove it afterwards
watermark.name = "WaterMark"
```

{{< gist "aspose-words-gists" "e9d8f984dac599756ccb4a64b8c79768" "Examples-DocsExamples-DocsExamples-Programming with Documents-Working with Graphic Elements-working_with_watermark-RemoveWatermark.py" >}}

## Add a Watermark in Table Cell

Sometimes you need to insert a watermark/image into a table's cell and display it outside the table, you can use the [is_layout_in_cell](https://reference.aspose.com/words/python-net/aspose.words.drawing/shapebase/is_layout_in_cell/) property. This property gets or sets a flag indicating whether the shape is displayed inside a table or outside of it. Note that this property works only when you optimize the document for Microsoft Word 2010 using the [optimize_for](https://reference.aspose.com/words/python-net/aspose.words.settings/compatibilityoptions/optimize_for/) method.

The following code example shows how to use this property:

{{< gist "aspose-words-gists" "e9d8f984dac599756ccb4a64b8c79768" "Examples-DocsExamples-DocsExamples-Programming with Documents-Working with Graphic Elements-working_with_shapes-LayoutInCell.py" >}}

------

## FAQ

1. **Q:** How can I add a text watermark with a specific font size and color?
   **A:** Create a `TextWatermarkOptions` object, set the `font_name`, `font_size`, and `color` properties, and then call `watermark.set_text("Your Text", options)`. Example:

   ```python
   from aspose.words import Document, Watermark, TextWatermarkOptions, Color
   doc = Document("input.docx")
   options = TextWatermarkOptions()
   options.font_name = "Arial"
   options.font_size = 72
   options.color = Color.gray
   Watermark.set_text(doc, "CONFIDENTIAL", options)
   doc.save("output.docx")
   ```

2. **Q:** How do I insert an image watermark from a file path or a stream?
   **A:** Use `ImageWatermarkOptions` and the `set_image` method. Provide either a file path, a byte array, or a stream to the image. Example:

   ```python
   from aspose.words import Document, Watermark, ImageWatermarkOptions
   doc = Document("input.docx")
   options = ImageWatermarkOptions()
   options.scale = 0.5   # optional scaling
   Watermark.set_image(doc, "logo.png", options)
   doc.save("output.docx")
   ```

3. **Q:** What is the recommended way to remove a watermark that was added with the `Watermark` class?
   **A:** Call the static `remove` method of the `Watermark` class, passing the document. This removes any watermark added via the `Watermark` API. Example:

   ```python
   from aspose.words import Document, Watermark
   doc = Document("watermarked.docx")
   Watermark.remove(doc)
   doc.save("clean.docx")
   ```

4. **Q:** I added a watermark as a `Shape`. How can I delete it later?
   **A:** Assign a unique name to the shape when you create it (e.g., `watermark.name = "MyWatermark"`). Later, retrieve the shape by name from the document’s node collection and remove it. Example:

   ```python
   from aspose.words import Document, Shape, ShapeType
   doc = Document("input.docx")
   shape = Shape(doc, ShapeType.TEXT_PLAIN_TEXT)
   shape.name = "MyWatermark"
   # ... configure shape as watermark ...
   doc.get_child_nodes(aw.NodeType.SHAPE, True).remove(shape)
   doc.save("output.docx")
   ```

5. **Q:** Can I place a watermark inside a table cell but have it appear outside the cell boundaries?
   **A:** Yes. Set the shape’s `is_layout_in_cell` property to `False` and ensure the document is optimized for Word 2010 using `CompatibilityOptions.optimize_for`. This forces the watermark to be rendered relative to the page rather than the cell. Example:

   ```python
   from aspose.words import Document, Shape, ShapeType, CompatibilityOptions, CompatibilityMode
   doc = Document("input.docx")
   shape = Shape(doc, ShapeType.IMAGE)
   shape.is_layout_in_cell = False
   doc.compatibility_options.optimize_for(CompatibilityMode.WORD_2010)
   # add shape to the desired cell
   doc.save("output.docx")
   ```
