Hello, world!

In this article, you will learn how to create a simple C# application that appends a text watermark using the GroupDocs.Watermark API.

Note
We assume that you already have a basic knowledge of Microsoft Visual Studio and C#.

Requirements

  • A compatible system with Microsoft Visual Studio installed. As an individual developer, you can use a free Visual Studio Community Edition.
  • 5 minutes of your spare time.

Preparing

  1. Open Visual Studio and go to File -> New -> Project.
  2. Select the Console App project type.
  3. Install GroupDocs.Watermark NuGet package to the project.

Coding

  1. Create an instance of the Watermarker class for the local document. You can specify an absolute or relative path:
    Watermarker watermarker = new Watermarker("C:\\Docs\\sample.docx")
    
  2. Create an instance of the TextWatermark class and specify the desired text and font for the watermark:
    TextWatermark watermark = new TextWatermark("Hello, world!", new Font("Arial", 36));
    
  3. Apply the watermark:
    watermarker.Add(watermark);
    
  4. Save the resulting document:
    watermarker.Save("C:\\Docs\\watermarked-sample.docx");
    

Full code:

using GroupDocs.Watermark;
using GroupDocs.Watermark.Watermarks;

// Specify an absolute or relative path to your document.
using (Watermarker watermarker = new Watermarker("C:\\Docs\\sample.docx"))
{
   // Specify the desired text and font for the watermark
   TextWatermark watermark = new TextWatermark("Test watermark", 
      new Font("Arial", 36, FontStyle.Bold | FontStyle.Italic));
      
   watermark.HorizontalAlignment = HorizontalAlignment.Center;
   watermark.VerticalAlignment = VerticalAlignment.Center;

   watermark.Opacity = 0.4;
   watermark.RotateAngle = 45;
   watermark.ForegroundColor = Color.Red;

    // Apply the watermark
    watermarker.Add(watermark);
    // Save the resulting document
    watermarker.Save("C:\\Docs\\watermarked-sample.docx");
}

Running

Run the program. A new watermarked document will appear in the specified path.

“Hello, world!” example

What’s next

Congratulations! You have added a simple text watermark to a document. Read the Developer guide and API reference to learn how to customize text watermarks, add images as watermarks, search documents for existing watermarks, and much more.