logo
search
Document Editing Problems

How to Add a Watermark to a Word Document via Open XML in .NET

Elise WilliamsElise Williams Sep 28, 2026 869 views

Question details

The user needs to programmatically add an image watermark to a Word document using DocumentFormat.OpenXml and .NET 6 without corrupting the file.

How to Add a Watermark to a Word Document with Open XML in .NET 6
Product
Microsoft Word / Open XML SDK
Device & OS
not provided
Scenario
Developing a .NET 6 application to programmatically edit WordprocessingML documents and insert an image as a watermark.
Observed behavior
Appending a drawing element directly to the document body corrupts the .docx file because the WordprocessingML schema strictly requires drawings to be placed inside valid paragraph and run structures.
Before you start

Ensure you have the latest DocumentFormat.OpenXml NuGet package installed in your .NET 6 project. Always create a backup of your target Word document before running programmatic modifications.

Solution 1Recommended

Build a Valid Paragraph and Run Structure for the Watermark

To prevent document corruption, encapsulate the Drawing element within a Run and Paragraph to comply with the strict WordprocessingML schema.

Directly injecting a Drawing element into the document body creates an invalid XML hierarchy in WordprocessingML. A valid structure demands that any inline or anchored picture is a child of a Run, which is a child of a Paragraph.

1
Create the Image Part

Add an ImagePart to the MainDocumentPart of your WordprocessingDocument and feed your watermark image stream into it. This generates a valid relationship ID.

2
Build the Drawing Element

Construct a Drawing object containing a valid Anchored or Inline picture element. Ensure that its Blip element references the relationship ID created in the previous step.

3
Encapsulate in Run and Paragraph

Create a new Run object and append your Drawing element to it. Next, create a new Paragraph object and append the Run to this Paragraph.

4
Append to Document Body

Finally, append the fully constructed Paragraph to the Body of the document, and call Save() on the MainDocumentPart to apply your changes without corrupting the file.

Build a Valid Paragraph and Run Structure for the Watermark
Best Practice for Traditional Watermarks: For a traditional watermark that displays consistently across all pages behind the text, it is standard practice to inject the Drawing into the document Header part rather than appending it to the Body.

Add Watermarks Easily with WPS Office

If you need to quickly add watermarks without writing C# code or dealing with complex Open XML schemas, WPS Writer provides an intuitive built-in watermark tool to handle the job perfectly.

  1. 1. Open your Document: Launch WPS Writer and open the .docx file you wish to watermark.
  2. 2. Navigate to the Insert Tab: Click on the 'Insert' tab located on the top ribbon menu.
  3. 3. Select the Watermark Tool: Click the 'Watermark' button and select 'Custom Watermark' from the dropdown list.
  4. 4. Apply Image or Text Watermark: Choose either a Picture or Text watermark, adjust the scaling and washout settings, and click 'OK' to instantly apply it to all pages safely.
Visual, click-and-apply watermark insertion without writing code.Full compatibility with Microsoft Word (.docx) formats and Open XML standards.Seamless and lightweight interface for all your document editing needs.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my Word document get corrupted when adding an image in Open XML?

Directly appending a Drawing element to the document body violates the WordprocessingML schema. Drawings must always be placed inside a Run element, which in turn must be contained within a Paragraph element.

Should a watermark go in the document body or the header?

For traditional background watermarks that appear behind the text on every page, you should place the anchored drawing in the Header part. Body watermarks are technically possible but only apply to the specific location where the paragraph resides.

Will documents modified with Open XML open correctly in WPS Office?

Yes, WPS Office is fully compatible with standard OOXML (.docx) files. Documents that are properly generated or modified using the Open XML SDK will open and render seamlessly in WPS Writer.