Add Watermark to PDF C#

Watermarks are an essential tool for protecting the integrity and ownership of digital documents. In this tutorial, you will explore how to add both textual and visual watermarks to PDF documents. Whether you’re looking to brand your documents or add copyright information, this step-by-step guide will help you to add text or image watermark using C#.

Add Watermark to PDF Online for Free

You can use this free app to add a watermark in PDF to insert any image or text watermark in a PDF document. You do not need to install any plugin or application as it is accessible using any web browser. You can set different text or image appearance properties like transparency, rotation, color, font, etc.

Insert Text or Image Watermark in PDF – C# API Installation

For inserting a watermark in a PDF document, you need to configure Conholdate.Total for .NET library. You may download it from the Releases section or install it with the following NuGet installation command:

Install-Package Conholdate.Total 

Add Text Watermark to PDF in C#

You can add a text watermark to a PDF document in C# by following the steps below:

  • Load the input PDF document.
  • Instantiate a TextStamp object.
  • Set the position and other appearance properties for the text watermark.
  • Set a Stamp ID for the text watermark to facilitate identification later.
  • Add the text watermark to a specific page.
  • Save the output PDF file with the added text watermark using the Document.Save() method.

The following sample code demonstrates how to add a text watermark to PDF in C#:

// Open document
Document pdfDocument = new Document("Input.pdf");
// Create text stamp
TextStamp textStamp = new TextStamp("CONFIDENTIAL");
// Set origin
textStamp.XIndent = 25;
textStamp.YIndent = 400;
// Set text properties
textStamp.TextState.Font = FontRepository.FindFont("Arial");
textStamp.TextState.FontSize = 72.0F;
textStamp.TextState.FontStyle = FontStyles.Italic;
textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Gray);
textStamp.Opacity = 50;
// Set Stamp ID for text watermark to later identify it
textStamp.setStampId(123456);
// Add stamp to particular page
pdfDocument.Pages[1].AddStamp(textStamp);
// Save output document
pdfDocument.Save("Add_Text_Watermark.pdf");

Add Image Watermark to PDF in C#

  • Load the input PDF document.
  • Retrieve a specific page from the input PDF.
  • Generate an image stamp.
  • Centrally position the image watermark.
  • Assign a unique stamp ID.
  • Apply the image stamp to a particular page or add it to all pages.
  • Save the modified PDF with the image watermark using the Document.Save() method.

The code snippet below shows how to add an image watermark to PDF in C#:

// Load input PDF document
Document pdfDocument = new Document("Input.pdf");
// Access any page of the input PDF
Page testpage = pdfDocument.Pages[1];
// Create image stamp
ImageStamp imageStamp = new ImageStamp("aspose-logo.png");
imageStamp.Background = true;
imageStamp.Height = 300;
imageStamp.Width = 300;
// Center adjust the image watermark based on page dimensions
imageStamp.XIndent = (testpage.PageInfo.Width / 2) - (imageStamp.Width / 2);
imageStamp.YIndent = (testpage.PageInfo.Height / 2) - (imageStamp.Height / 2);
imageStamp.Opacity = 0.5;
// Set stamp id for deleting the watermark later, if required
imageStamp.setStampId(12345678);
// Add stamp to particular page
//pdfDocument.Pages[1].AddStamp(imageStamp);
// Add stamp to each page of PDF
foreach (Page page in pdfDocument.Pages)
{
page.AddStamp(imageStamp);
}
// Save output document
pdfDocument.Save("Add_Image_Watermark.pdf");

Get a Free Evaluation License

You may get a free temporary license to evaluate the API to its full capacity without any evaluation limitations.

Conholdate.Total for .NET - Learning Resources

Please refer to the following resources to further explore the learning material and understand different features:

Summing Up

In this tutorial, we explored how to add both text and image watermarks to PDF documents using C#. By following the step-by-step instructions, you can enhance your PDF documents with personalized watermarks to protect your content or add branding. In case of any queries, please feel free to reach out to us at the free support forum.

See Also