Watermark Protected Docs using C#

Watermarking is one of the ways to protect your documents from illegal use; branding your files; mentioning your documents as drafts or confidential. In order to watermark your files programmatically, this article guides you on how to add watermark to your password-protected files using C#. We will separately look into adding text and image watermarks to the protected files.

The following topics are discussed here:

.NET API to Watermark Password Protected Files

GroupDocs.Watermark provides a watermarking solution and showcases .NET API that allows working with watermarks within .NET applications. I will use this API to add text and image watermarks to password-protected files.

You can download the DLLs or MSI installer from the downloads section or install the API in your .NET application via NuGet.

PM> Install-Package GroupDocs.Watermark

Adding Watermark to Password-Protected Files using C#

It’s quite simple; just a few lines of code allow you to put a watermark in your files. Just follow the following steps for adding either type of watermark.

  • Load the protected document/file.
  • Apply text/image watermark.
  • Save the watermarked file.

Let’s separately see how to add text watermarks, and then image watermarks.

Add Text Watermark to Protected Files using C#

Text watermarks are most used to put the company name within documents; mention the document as DRAFT or CONFIDENTIAL; or any other similar reasons. The following steps guide how to insert text watermark to password-protected files using C#.

  • Prepare the loading option using exsiting password.
  • Load the protected file using Watermarker class and loading option.
  • Prepare the watermark using TextWatermark class.
  • Set the watermark’s text, appearance, rotation, opacity, color, and other properties.
  • Add watermark to document using Add() method.
  • Save the watermarked file using the Save() method.

The following C# code inserts a text watermark to a protected PDF document.

Add Image Watermark to Protected Files using C#

If you want to insert your logo or some other image as a watermark, you can add it using the ImageWatermark class. The following steps allow you to add an image watermark to your password-protected documents using C#.

  • Prepare the loading option using exsiting password.
  • Load the protected file using Watermarker class and loading option.
  • Load the watermark image file using ImageWatermark class.
  • Set the watermark’s appearance, alignment, coordinates, rotation, opacity, and other properties.
  • Add watermark to document using Add() method.
  • Save the watermarked file using the Save() method.

The following C# code inserts an image watermark to the protected MS Word DOCX document.

Get a Free API License

You can use the APIs for free by getting a temporary license.

Conclusion

To conclude, we learned to add text watermarks, as well as image watermarks to password-protected files within the .NET applications using C#. Further, we added a few customizations to the appearance of watermarks while adding.

Similarly, you can apply watermarks to the selective pages of documents, chosen slides of the presentations, and specific sheets of workbooks within your documents. See the related articles for details.

To learn more about GroupDocs.Watermark for .NET, visit its documentation. For queries, contact us via the forum.

Related Articles