How to Add a Watermark to a Word Document via Open XML in .NET
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.

- 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.
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.
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.
Add an ImagePart to the MainDocumentPart of your WordprocessingDocument and feed your watermark image stream into it. This generates a valid relationship ID.
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.
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.
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.

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. Open your Document: Launch WPS Writer and open the .docx file you wish to watermark.
- 2. Navigate to the Insert Tab: Click on the 'Insert' tab located on the top ribbon menu.
- 3. Select the Watermark Tool: Click the 'Watermark' button and select 'Custom Watermark' from the dropdown list.
- 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.

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.




