C#/VB.NET: Insert Watermarks in Word

Watermarks are text or images displayed fadedly or in gray color in the background of a Word document. They can be used to declare confidentiality, copyright, or other attributes of the document, or just as decorations to make the document more attractive. This article shows an easy way to insert watermarks in Word documents with the help of Spire.Doc for .NET, including text watermarks and image watermarks.

Install Spire.Doc for .NET

To begin with, you need to add the DLL files included in the Spire.Doc for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.Doc

Insert a Text Watermark in a Word Document

The detailed steps are as follows:

  • Create an object of Document class.
  • Load a Word document from disk using Document.LoadFromFile() method.
  • Insert a text watermark in the document using custom method InsertTextWatermark().
  • Save the document using Doucment.SaveToFile() method.
  • C#
  • VB.NET
using System;
using System.Drawing;
using Spire.Doc;
using Spire.Doc.Documents;

namespace InsertImageWatermark
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Create an object of Document class
            Document document = new Document();

            //Load a Word document from disk
            document.LoadFromFile(@"D:\Samples\Sample.docx");

            //Insert a text watermark
            InsertTextWatermark(document.Sections[0]);

            //Save the document
            document.SaveToFile("InsertTextWatermark.docx", FileFormat.Docx);
        }
        private static void InsertTextWatermark(Section section)
        {
            TextWatermark txtWatermark = new TextWatermark();
            txtWatermark.Text = "DO NOT COPY";
            txtWatermark.FontSize = 50;
            txtWatermark.Color = Color.Blue;
            txtWatermark.Layout = WatermarkLayout.Diagonal;
            section.Document.Watermark = txtWatermark;

        }
    }
}

C#/VB.NET: Insert Watermarks in Word

Insert an Image Watermark in a Word Document

The detailed steps are as follows:

  • Create an object of Document class.
  • Load a Word document from disk using Document.LoadFromFile() method.
  • Insert an image watermark in the document using custom method InsertImageWatermark().
  • Save the document using Document.SaveToFile() method.
  • C#
  • VB.NET
using System;
using System.Drawing;
using Spire.Doc;
using Spire.Doc.Documents;

namespace InsertWatermark
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Create an object of Document class
            Document document = new Document();

            //Load a Word document from disk
            document.LoadFromFile(@"D:\Samples\Sample.docx");

            //Insert an image watermark
            InsertImageWatermark(document);

            //Save the document
            document.SaveToFile("InsertImageWatermark.docx", FileFormat.Docx);        
        }
        private static void InsertImageWatermark(Document document)
        {
            PictureWatermark picture = new PictureWatermark();
            picture.Picture = Image.FromFile(@"D:\Samples\Watermark.png");
            picture.Scaling = 200;
            picture.IsWashout = false;
            document.Watermark = picture;
        }
    }
}

C#/VB.NET: Insert Watermarks in Word

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.