Watermark PDF Files in C#

Watermarks are frequently used in PDF to ensure the protection of the content. You can insert or delete text and image watermarks in PDF files with a few simple steps. This article demonstrates a quick and high-quality PDF watermarking method using C# PDF library. So let’s see how to add a watermark to a PDF in C#. We will explicitly cover how to add image and text watermarks in PDF files in C#.

C# PDF Watermarking Library

To add a watermark in PDF files, we will use Aspose.PDF for .NET. The library lets you create, edit, and manipulate your PDF files seamlessly. Also, you can easily work on adding or removing 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

Watermark PDF Files in C#

The following sections cover how to add image and text watermarks in a PDF file.

How to Add Text Watermark in PDF in C#

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

The following are the steps to add a text watermark in a PDF file in C#.

  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 a text watermark using Document.Save() method.

The following code snippet shows how to add a text watermark in a PDF file in C#.

C# Add Image Watermark in PDF

Images contain a lot of meaningful information so the image watermarks are also frequently used in PDF files. For example, a document issued by some organization or institute may have its logo in the background of the page. To add an image watermark to PDF, you follow 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 a particular page OR on all pages.
  7. Save output PDF with image watermark using Document.Save() method.

The code snippet below shows how to insert an image watermark in a PDF using C#.

The following screenshot shows the image watermark on the PDF.

Image Watermark PDF

Remove Watermark from a PDF in C#

You can easily remove a watermark from a PDF document. An image watermark or text watermark can be identified with a stamp ID property, which was set in the above examples while adding the watermarks.

The following are the steps to remove a watermark from PDF in C#.

  1. Initialize PdfContentEditor class object.
  2. Call BindPdf method.
  3. Delete the watermark using a specific ID.
  4. Save the output PDF using Document.Save() method.

The code below shows how to remove an image or text watermark from PDF in C#.

Free C# Library to Watermark PDF

You can get a free temporary license to watermark your PDF files without any limitations.

Explore C# PDF Library

You can explore more about the C# PDF watermarking library using the documentation. Also, you can post your queries on our forum.

Conclusion

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

See Also