Add Watermark to Word Documents using REST API in C#

Add Watermark to Word Documents using REST API in C#

You can add a text or an image as a watermark to your Word documents programmatically on the cloud. The watermarks are used to identify the document’s creator or other information such as copyright or logo, etc.  Usually, the watermark is used in the form of a superimposed image, logo, pattern, or text placed inside the document. In this article, you will learn how to add a watermark to Word documents using a REST API in C#.

The following topics shall be covered in this article:

Watermark REST API and .NET SDK

For adding text or image watermark to DOCX files, I will be using the .NET SDK of GroupDocs.Watermark Cloud API. It allows you to programmatically add, remove, search and replace watermarks from images and documents of the supported file formats such as PDF, Microsoft Word, and Powerpoint. Moreover, you can control the customization of watermarks by specifying the text style, font, size, color, or position as per your requirements. Currently, it also provides Java SDK for the Cloud API.

You can install GroupDocs.Watermark Cloud into your Visual Studio project from the NuGet Package Manager or using the following command in the Package Manager console:

Install-Package GroupDocs.Watermark-Cloud

Please get your Client ID and Secret from the dashboard before following the mentioned steps. Once you have your ID and secret, add in the code as shown below:

Add Text Watermark to Word Documents using REST API in C#

You can add any text as a watermark to your Word documents programmatically by following the simple steps mentioned below:

Upload the Document

Firstly, upload the Word document to the Cloud using the code example given below:

As the result, the DOCX file will be uploaded to the cloud storage and will be available in the files section of your dashboard.

Add Text Watermark to DOCX using C#

You can add a text watermark to the DOCX file programmatically by following the steps given below.

  • Create an instance of the WatermarkApi
  • Create an instance of the FileInfo
  • Set the DOCX file path
  • Create WatermarkOptions and set FileInfo
  • Create TextWatermarkOptions
  • Set Text, Font FamilyFont Size, and the Text Alignment
  • Set Foreground color of the watermark text
  • Define the watermark Position
  • Define WatermarkDetails and set TextWatermarkOptions and Position
  • Create AddRequest with WatermarkOptions
  • Get results by calling the WatermarkApi.add() method

The following code sample shows how to add text as a watermark to a Word document using a REST API in C#.

Add Text Watermark to Word Documents using REST API in C#
Add Text Watermark to Word Documents using REST API in C#

Download the Updated File

The above code sample will save the Word file with a text watermark on the cloud. You can download it using the following code sample:

Add Image Watermark to Word Documents using REST API

You can add an image or a logo as a watermark to your Word documents programmatically by following the steps given below.

  • Create an instance of the WatermarkApi
  • Create an instance of the FileInfo
  • Set the DOCX file path
  • Create WatermarkOptions and set FileInfo
  • Create ImageWatermarkOptions
  • Set FilePath of a PNG image to watermark with
  • Define the watermark Position
  • Create WatermarkDetails
  • Set ImageWatermarkOptions and Position
  • Set WatermarkDetails to List
  • Create AddRequest with WatermarkOptions
  • Get results by calling the WatermarkApi.add() method

The following code sample shows how to add an image as a watermark to DOCX using a REST API in C#. Please follow the steps mentioned earlier to upload and download the files.

Add Image Watermark to Images using REST API in C#
Add Image Watermark to Word Documents using REST API in C#

Try Online

Please try the following free online Watermark tool, which is developed using the above API. https://products.groupdocs.app/watermark/docx

Conclusion

In conclusion, you have learned how to add text or image watermark to a Word document on the cloud. You have also learned how to programmatically upload the DOCX files on the cloud and then download the updated file from the cloud. You can learn more about GroupDocs.Watermark Cloud API from the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser. In case of any ambiguity, feel free to contact support.

See Also