Document watermarks are a common requirement in office automation workflows. Whether used to protect intellectual property, indicate document status, or add branding elements, watermarks provide visual identification without obstructing the main content.
This tutorial demonstrates how to use Python to add both text and image watermarks to Word documents. The methods introduced here are suitable for batch processing company reports, adding confidentiality labels, or creating branded document templates.
Environment Setup
Install the required library using pip:
pip install Spire.Doc
Spire.Doc for Python provides a comprehensive API for Word document manipulation, including watermark insertion, document property management, and format conversion.
Add a Text Watermark
Text watermarks are commonly used to indicate document status, such as “Draft,” “Confidential,” or to add copyright notices. The following example demonstrates how to insert a diagonal text watermark:
from spire.doc import *
from spire.doc.common import *
# Load an existing document
document = Document()
document.LoadFromFile("./Data/Template.docx")
# Create a text watermark object
txtWatermark = TextWatermark()
txtWatermark.Text = "Confidential"
txtWatermark.FontSize = 95
txtWatermark.Color = Color.get_Blue()
txtWatermark.Layout = WatermarkLayout.Diagonal
# Apply the watermark to the document
document.Watermark = txtWatermark
# Save and close
document.SaveToFile("TextWaterMark.docx", FileFormat.Docx)
document.Close()
Output:
Code Execution Steps
-
Document()creates a new document object -
LoadFromFile()opens the target Word document -
TextWatermark()initializes a watermark object - Properties such as
Text,FontSize,Color, andLayoutdefine the watermark appearance - Assigning it to
document.Watermarkapplies it to all pages -
SaveToFile()exports the result
Key Property Descriptions
-
Text: The content displayed as the watermark -
FontSize: Controls the font size; typically set to a large value (90–100) to span the page -
Color: Defines the watermark color; usually a light or semi-transparent color to avoid covering the main content -
Layout: Determines orientation —Diagonalfor slanted placement,Horizontalfor straight alignment
Add an Image Watermark
Image watermarks are ideal for adding company logos, signatures, or custom graphics:
from spire.doc import *
from spire.doc.common import *
document = Document()
document.LoadFromFile("./Data/Template.docx")
# Create an image watermark
picture = PictureWatermark()
picture.SetPicture("./Data/ImageWatermark.png")
picture.Scaling = 80
picture.IsWashout = False
# Apply the image watermark
document.Watermark = picture
document.SaveToFile("ImageWaterMark.docx", FileFormat.Docx)
document.Close()
Output:
Important Parameter Descriptions
-
SetPicture(): Loads an image file (PNG, JPG, etc.) as the watermark -
Scaling: Adjusts the size as a percentage (e.g., 250 = 2.5× original size) -
IsWashout:-
False: Keeps original colors -
True: Applies a faded effect for a softer appearance
-
Compared to text watermarks, image watermarks offer stronger visual impact and are especially suitable for branding. Adjusting the Scaling parameter ensures proper display across different page sizes.
Practical Tips
Choosing Watermark Colors
Select colors that balance visibility and professionalism:
- Blue (
Color.get_Blue()): A professional choice for business documents - Gray: Subtle and unobtrusive
- Red (
Color.get_Red()): Suitable for warnings or confidential markings
Layout Options
The Layout property controls watermark orientation:
-
WatermarkLayout.Diagonal: Slanted from corner to corner (most commonly used) -
WatermarkLayout.Horizontal: Horizontally aligned
Choose based on document content and visual preference.
Combining with Other Operations
Watermark insertion is often part of a broader document processing workflow. It can be combined with:
- Batch processing multiple files
- Setting document properties (author, keywords)
- Converting to PDF after adding watermarks
- Extracting content statistics
Conclusion
Adding watermarks to Word documents programmatically enables efficient batch processing and consistent document branding. The techniques introduced here are applicable to various scenarios, including copyright protection, status labeling, and corporate identity management.
By automating watermark insertion, organizations can ensure all documents maintain a professional standard while reducing manual workload.


Top comments (0)