Insert or Delete Text/Image Watermark in PDF File using C#

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:

Add or Delete Image/Text Watermark in PDF – API Installation

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.

Insert Text Watermark in PDF File Programmatically using C#

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#:

Insert Image Watermark in PDF File Programmatically using 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

Delete Image or Text 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 insert image watermark or text watermark in a PDF document programmatically using C#. Likewise, we have also explored how to delete image or text watermark in PDF file using C# language in .NET based applications. Furthermore, in case of any further query or information, you can write to us at Free Support Forum.

See Also

Convert PDF File to Byte Array or Byte Array to PDF using C#