This quick guide describes how to add watermark to PDF in C# by using any image or some text as a watermark. To add watermark to PDF C# code with detailed description is provided. There is no need to install any third-party tool or software to accomplish the task.
Steps to Add Watermark to PDF in C#
- Configure the project to add Aspose.PDF for .NET from the NuGet package manager to add a watermark
- Load the target PDF file into the Document class object to which the watermark is to be added
- Load the image into the ImageStamp class object that is to be used as a watermark
- Configure the loaded image characteristics before adding as a watermark
- Add the watermark image to the selected page
- Save the PDF having a watermark in it
These steps describe how does C# add watermark to PDF by first pointing to the necessary resources required to run the sample code and then sharing a step-by-step approach to perform the task. You should load the target PDF and image files in the relevant class objects and then set the loaded image properties like its location on the page, its height, and width and set the flag to display it in the background or not. You can add the watermark image to any of the selected pages in the PDF before saving it back on the disk.
Code to Add Watermark to PDF in C#
By using C# PDF watermark can be added in different ways like the image is used as a watermark in this code sample. However, you can also use text watermark by setting the desired text in the constructor of Aspose.Pdf.TextStamp class object. It provides the option to set the text properties like font, background color, and foreground color before adding the watermark using the Aspose.Pdf.Page.AddStamp() function similar to adding the image watermark in the above example.
This tutorial has guided us to add watermark to PDF however, if you are interested in creating the PDF from scratch, refer to the article on how to create PDF in C#.