DEV Community

Jeremy K.
Jeremy K.

Posted on

Adding Watermarks to Word with C#: Text & Image

Adding watermarks to Word documents is a staple of office workflows - whether marking drafts, labeling confidential files, or embedding company logos for anti-counterfeiting. Manual watermarking becomes impractical for batch processing; automation via code is the efficient alternative.

This guide walks you through a lightweight, beginner-friendly method to add text and image watermarks to Word documents using C# and the free library Free Spire.Doc for .NET. No Office installation required—simple, reliable, and easy to implement.


⚙️ 1. Install Free Spire.Doc

Free Spire.Doc for .NET is a free Word processing library that simplifies manipulating document elements (including watermarks). Install it via NuGet in Visual Studio:

  1. Right-click your project in Solution Explorer.
  2. Select Manage NuGet Packages.
  3. Search for "FreeSpire.Doc" and click Install.

✅ 2. Adding Text Watermarks: C# Implementation

Text watermarks (e.g., "Confidential", "Internal Use") are the most common type. Free Spire.Doc’s TextWatermark class lets you customize content, font, color, and layout in just a few lines of code.

Full Code Example

using System;
using Spire.Doc;
using Spire.Doc.Documents;
using System.Drawing;

namespace WordTextWatermarkDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            // 1. Load the target Word document (.doc/.docx supported)
            Document doc = new Document();
            doc.LoadFromFile(@"C:\Docs\SampleDocument.docx");

            // 2. Create and configure the text watermark
            TextWatermark textWatermark = new TextWatermark
            {
                Text = "Confidential Document",  // Watermark text
                FontName = "Microsoft YaHei",    // Font
                FontSize = 40,                   // Font size
                Color = Color.LightGray,         // Light gray to avoid obscuring content
                Layout = WatermarkLayout.Diagonal // Layout: Diagonal or Horizontal
            };

            // 3. Apply the watermark to the document
            doc.Watermark = textWatermark;

            // 4. Save and close the document
            doc.SaveToFile(@"C:\Docs\Document_With_TextWatermark.docx", FileFormat.Docx2013);
            doc.Close();

            Console.WriteLine("Text watermark added successfully!");
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

✅ 3. Adding Image Watermarks: Embed Logos or Graphics

For image-based watermarks (e.g., company logos, copyright badges), use Free Spire.Doc’s PictureWatermark class. It supports custom scaling to ensure the image doesn’t overshadow the main content.

Full Code Example

using System;
using Spire.Doc;
using Spire.Doc.Documents;

namespace WordImageWatermarkDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            // 1. Load the Word document
            Document doc = new Document();
            doc.LoadFromFile(@"C:\Docs\SampleDocument.docx");

            // 2. Create and configure the image watermark
            PictureWatermark imageWatermark = new PictureWatermark
            {
                // Load image (supports .png, .jpg, etc.)
                Picture = System.Drawing.Image.FromFile(@"C:\Images\CompanyLogo.png"),
                Scaling = 50,         // Scale to 50% of original size
                IsWashout = false     // Disable washout for clearer logo (set to true for transparency)
            };

            // 3. Apply the watermark
            doc.Watermark = imageWatermark;

            // 4. Save the result
            doc.SaveToFile(@"C:\Docs\Document_With_ImageWatermark.docx", FileFormat.Docx2013);
            doc.Close();

            Console.WriteLine("Image watermark added successfully!");
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

⚠️ 4. Key Considerations

① Free Version Limitations

The Free Spire.Doc supports documents with up to 500 paragraphs and adds no extra watermarks—ideal for personal or small-scale projects.

② Path Best Practices

Use absolute file paths (e.g., @"C:\Docs\File.docx") when loading documents/images. Relative paths may cause "file not found" errors if the working directory changes.

③ Targeted Watermarking

The code above adds watermarks to the entire document. To watermark specific pages (e.g., only the first page), target a document section directly:

// Apply watermark only to the first section (first page)
doc.Sections[0].Watermark = textWatermark; 
Enter fullscreen mode Exit fullscreen mode

⚡️ 5. Why This Solution Stands Out

Unlike Office Interop (which requires local Office installation and has poor performance), Free Spire.Doc for .NET offers:

  • Lightweight deployment: No external dependencies.
  • High stability: Avoids compatibility issues with Office versions.
  • Simplified code: Intuitive APIs reduce development time.

The workflow is consistent for both text and image watermarks:

Load Document → Create Watermark Object → Configure Properties → Apply & Save.

Top comments (0)