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#.
- Add or Delete Image/Text Watermark in PDF – API Installation
- Insert Text Watermark in PDF File Programmatically using C#
- Insert Image Watermark in PDF File Programmatically using C#
- Delete Image or Text Watermark in PDF File using 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.
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#.
- Load input PDF document.
- Create TextStamp class instance.
- Set origin and other properties.
- Set Stamp ID for text watermark to later identify it.
- Add a stamp to a particular page.
- 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.
- Load input PDF document.
- Access any page of the input PDF.
- Create image stamp.
- Center adjust the image watermark based on page dimensions.
- Set stamp id for deleting the watermark later, if required.
- Add a stamp to a particular page OR on all pages.
- 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.
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#.
- Initialize PdfContentEditor class object.
- Call BindPdf method.
- Delete the watermark using a specific ID.
- 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
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.