Skip to main content
A newer version of this page is available. .
All docs
V21.1

Watermarks in Word Documents

  • 3 minutes to read

A watermark is a faded background image or text displayed behind document content. Word Processing Document API allows you to create and remove watermarks in DOCX, DOC, and RTF documents. You can also print and export documents with watermarks to PDF.

watermarks

Run Demo: Word (RTF) Watermarks

Create a Watermark

A watermark is located in the section header. If the document does not contain headers, you cannot add a watermark. Refer to the following article for an example on how to create headers: Headers and Footers.

If the document has multiple sections, the WatermarkManager adds the same watermark to each section and to each available header type (first, primary, odd, or even).

The WatermarkManager.Type property indicates whether the document has watermarks. The property returns WatermarkType.None if the document does not contain watermarks.

Example: Create a Text Watermark

The code sample below adds a text watermark:

image

using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
    wordProcessor.LoadDocument("DocumentProtection.docx");

    // Check whether the document sections have headers:
    foreach (Section section in wordProcessor.Document.Sections)
    {
        if (!section.HasHeader(HeaderFooterType.Primary))
        {
            // If not, create an empty header
            SubDocument header = section.BeginUpdateHeader();
            section.EndUpdateHeader(header);
        }
    }

    TextWatermarkOptions textWatermarkOptions = new TextWatermarkOptions();
    textWatermarkOptions.Color = System.Drawing.Color.LightGray;
    textWatermarkOptions.FontFamily = "Calibri";
    textWatermarkOptions.Layout = WatermarkLayout.Diagonal;
    textWatermarkOptions.Semitransparent = true;

    wordProcessor.Document.WatermarkManager.SetText("CONFIDENTIAL", textWatermarkOptions);
    wordProcessor.SaveDocument("DocumentProtection_new.docx", DocumentFormat.OpenXml);
}

Example: Create an Image Watermark

The code sample below adds an image watermark:

result

using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
    wordProcessor.LoadDocument("DocumentProtection.docx");

    // Check whether the document sections have headers:
    foreach (Section section in wordProcessor.Document.Sections)
    {
        if (!section.HasHeader(HeaderFooterType.Primary))
        {
            // If not, create an empty header
            SubDocument header = section.BeginUpdateHeader();
            section.EndUpdateHeader(header);
        }
    }

    ImageWatermarkOptions imageWatermarkOptions = new ImageWatermarkOptions();
    imageWatermarkOptions.Washout = false;
    imageWatermarkOptions.Scale = 1.5;
    wordProcessor.Document.WatermarkManager.SetImage(Image.FromFile("DevExpress.png"), imageWatermarkOptions);
    wordProcessor.SaveDocument("DocumentProtection_new.docx", DocumentFormat.OpenXml);
}

Remove the Watermark

The code sample below checks the watermark type and removes it:

using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
    wordProcessor.LoadDocument("FirstLook.docx");
    WatermarkManager watermarkManager = 
        wordProcessor.Document.WatermarkManager;
    if (watermarkManager.Type == WatermarkType.Image)
    {
         watermarkManager.Remove();
    }

    wordProcessor.SaveDocument("FirstLook_new.docx", DocumentFormat.OpenXml);
}

Limitations

The following features are not available: