In this article, you will learn how to add or remove watermark in PDF documents programmatically in C# .NET.

Watermarks are frequently used in PDF files. You can insert or delete text and image watermark in PDF files with few simple steps. You can easily control a lot of properties for working with watermarks. For example, opacity, position, rotation, color, font, image, etc., and much more. Likewise, a lot of other properties can be set for watermarks with quick API calls.

Let us explore this topic further by walking through the following sections:

C# .NET API to Add or Remove Watermark in PDF – Free Download

Aspose.PDF for .NET API lets you create, edit, and manipulate your PDF documents. You can easily work with the feature of adding or deleting watermarks in PDF documents. You can download the latest DLL files from the New Releases section, or install them with the following NuGet command:

PM> Install-Package Aspose.Pdf

The API will be configured within a couple of minutes and now you are all set to work with watermarks in PDF documents.

Add Text Watermark in PDF File in C# .NET

Text watermarks are frequently used in PDF documents to show the purpose or nature of the document. For example, some organization may add a text watermark as “Classified” or “Confidential” based on the nature of the document. Likewise, you can control the font size, font style, color, rotation, position, etc. You can add a text watermark in PDF file with the following steps:

  1. Load input PDF document
  2. Create TextStamp class instance
  3. Set origin and other properties
  4. Set Stamp ID for text watermark to later identify it
  5. Add a stamp to a particular page
  6. Save output PDF with text watermark

The following code snippet explains how to add or insert text watermark in PDF file using C#:

Add Image Watermark in PDF File in C#

Images contain a lot of meaningful information so the image watermarks are also frequently used in PDF files. For example, a document issued from some organization or institute may have its logo in the background of the page. You can work with the feature of inserting image watermark in PDF documents using C# with the steps below:

  1. Load input PDF document
  2. Access any page of the input PDF
  3. Create image stamp
  4. Center adjust the image watermark based on page dimensions
  5. Set stamp id for deleting the watermark later, if required
  6. Add a stamp to particular page OR on all pages
  7. Save output PDF with image watermark

The code snippet below shows how to insert image watermark in PDF file with C#:

You can notice the centrally aligned image watermark of the PDF file in the screenshot:

Image Watermark PDF

Remove Watermark in PDF File using C#

You can remove/delete a watermark from a PDF document. An image watermark or text watermark can be identified with a stamp id property which was set in above examples while adding the watermarks. You need to follow the steps below to delete watermark from PDF file:

  1. Initialize PdfContentEditor class object
  2. Call BindPdf method
  3. Delete watermark using specific id
  4. Save output PDF with removed watermark

The code below shows how to delete image or text watermark from PDF file in C#:

Conclusion

In this article, you have learned how to add image watermark or text watermark in a PDF document programmatically in C#. Likewise, we have also explored how to remove image or text watermark in PDF file using C# in .NET applications. Furthermore, in case of any query or information, you can write to us at Free Support Forum.

See Also