Step-by-Step Guide to Adding and Removing Watermarks in PDF using C#
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (174).NET Core  (29).NET MAUI  (207)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (40)Black Friday Deal  (1)Blazor  (215)BoldSign  (14)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (66)Flutter  (133)JavaScript  (221)Microsoft  (118)PDF  (81)Python  (1)React  (100)Streamlit  (1)Succinctly series  (131)Syncfusion  (914)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (36)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (147)Chart  (131)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (628)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (40)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (507)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (592)What's new  (332)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Step-by-Step Guide to Adding and Removing Watermarks in PDF using C#

Step-by-Step Guide to Adding and Removing Watermarks in PDF using C#

A watermark refers to a design, pattern, or text applied to a digital or physical document, image, or video to signify its ownership or authenticity. Typically, watermarks are transparent and strategically placed so as not to disrupt the content while still being visible enough to indicate the source of the material.

This advantageous feature can be utilized in various contexts, including branding and marketing, safeguarding against unauthorized usage, identifying and attributing the source of content, and ensuring document security, authenticity, and verification.

The Syncfusion .NET PDF Library supports adding image or text watermarks to a PDF document to indicate the authenticity or ownership of the document. The library provides APIs for programmatically adding watermarks to PDF documents, with options for customizing the watermark’s position, size, and opacity.

This article will cover creating a watermark for a PDF file using the Syncfusion .NET PDF Library.

Agenda:

Experience a leap in PDF technology with Syncfusion's PDF Library, shaping the future of digital document processing.

Getting started with app creation

  1. Create a new C# .NET console application project.
    Select the Console App option
  1. Install the Syncfusion.Pdf.Net.Core NuGet package as a reference to your .NET standard applications from NuGet.org.
    Install the Syncfusion.Pdf.Net.Core NuGet package

Add a text watermark to a PDF using C#

Text watermarks are a practical technique for maintaining document security, intellectual property protection, and branding initiatives.

Follow these steps to add a text watermark to a PDF file using the Syncfusion PDF Library:

  1. Use the PdfLoadedDocument class to load an existing PDF document.
  2. Then, get the page reference (where you want to include the watermark text) in the PdfLoadedPage object.
  3. Create an instance of the PdfWatermarkAnnotation class and customize the location, size, and opacity.
  4. Include the watermark text using the DrawString method.
  5. Add the watermark annotation to the annotations collection.
  6. Finally, save the PDF file using the Save method.

The following code example adds a text watermark in a PDF document using C#.

//Load the PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream);

//Get the page.
PdfLoadedPage lpage = loadedDocument.Pages[0] as PdfLoadedPage;

//Creates PDF watermark annotation. 
PdfWatermarkAnnotation watermark = new PdfWatermarkAnnotation(new RectangleF(100, 300, 400, 400));

//Sets properties to the annotation. 
watermark.Opacity = 0.5f;

//Create the appearance of watermark. 
watermark.Appearance.Normal.Graphics.DrawString("Imported using Essential PDF", new PdfStandardFont(PdfFontFamily.Helvetica, 20), PdfBrushes.Red, new RectangleF(50, 50, 250, 50), new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle));

//Adds the annotation to page. 
lpage.Annotations.Add(watermark);
FileStream stream = new FileStream("Output.pdf", FileMode.Create);

//Save the modified document to file.
loadedDocument.Save(stream);

//Close the PDF document.
loadedDocument.Close(true);
stream.Close();

Execute this code example to get a text watermarked PDF like the following screenshot.

Text watermark added in a PDF file
Text watermark added in a PDF file

Unleash the full potential of Syncfusion's PDF Library! Explore our advanced resources and empower your apps with cutting-edge functionalities.

Add image watermark to a PDF using C#

Image watermarks can be useful for protecting your intellectual property, establishing your brand identity, adding security features to your documents, and indicating confidentiality.

Follow these steps to add an image watermark to a PDF file using the Syncfusion PDF Library: 

  1. Use the PdfLoadedDocument class to load an existing PDF document.
  2. Then, get the page reference (where you want to include the watermark image) in the PdfLoadedPage object.
  3. Create an instance of the PdfWatermarkAnnotation class.
  4. Customize the size, location, and opacity of the watermark instance.
  5. Load the image from a file to the PdfBitmap object.
  6. Draw the image on the graphics of the watermark instance using the DrawImage method.
  7. Add the watermark annotation to the annotation collection of the page.
  8. Finally, save the PDF file using the Save method.

The following code example adds an image watermark in a PDF document using C#.

//Load the PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);

//Get the page. 
PdfLoadedPage lpage = loadedDocument.Pages[0] as PdfLoadedPage;

//Creates PDF watermark annotation. 
PdfWatermarkAnnotation watermark = new PdfWatermarkAnnotation(new RectangleF(100, 300, 400, 400));

//Sets properties to the annotation. 
watermark.Opacity = 0.5f;

//Create the appearance of watermark. 
FileStream imageStream = new FileStream(“Image.jpg”, FileMode.Open, FileAccess.Read);
PdfImage image = new PdfBitmap(imageStream);
watermark.Appearance.Normal.Graphics.DrawImage(image, new PointF(0, 0));

//Adds the annotation to page. 
lpage.Annotations.Add(watermark);
FileStream stream = new FileStream("output.pdf", FileMode.Create);

//Save the modified document to file.
loadedDocument.Save(stream);

//Close the PDF document.
loadedDocument.Close(true);
stream.Close();

Execute this code example to get an image watermarked PDF document like the following screenshot.

Image watermark added in the PDF file
Image watermark added in the PDF file

See a world of document processing possibilities in Syncfusion's PDF Library as we unveil its features in interactive demonstrations.

Remove a watermark from a PDF using C#

Removing a watermark from a PDF document can be useful in cases where the watermark is no longer needed or when the PDF file needs to be shared without the watermark.

Follow these steps to remove a watermark from a PDF file using the Syncfusion PDF Library: 

  1. Use the PdfLoadedDocument class to load an existing PDF document.
  2. Get the reference for the page (where you want to remove the watermark) in the PdfLoadedPage object.
  3. Get the watermark annotation using the PdfLoadedAnnotation class.
  4. Remove the watermark by passing the index value to the RemoveAt method.
  5. Finally, save the PDF file using the Save method.

The following code example removes a watermark from a PDF using C#.

//Load the PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);
for (int i = 0; i < loadedDocument.Pages.Count; i++)
{
  //Get the page. 
  PdfLoadedPage lpage = loadedDocument.Pages[i] as PdfLoadedPage;

  //Gets the annotation collection.
  PdfLoadedAnnotationCollection annotations = lpage.Annotations;
  for (int j = 0; j < annotations.Count; j++)
  {
      //Gets the annotation.
      PdfLoadedAnnotation annotation = lpage.Annotations[j] as PdfLoadedAnnotation;
      if (annotation != null && annotation is PdfLoadedWatermarkAnnotation)
      {
          //Removes the first annotation.
          annotations.RemoveAt(j);
      }
   }
} 
FileStream stream = new FileStream("output.pdf", FileMode.Create);

//Save the modified document to file.
loadedDocument.Save(stream);

//Close the PDF document.
loadedDocument.Close(true);
stream.Close();

Execute this code example to remove a watermark from a PDF document like in the following screenshot.

Watermark removed from a PDF file
Watermark removed from a PDF file

GitHub reference

You can find examples for doing this in the GitHub repository.

Syncfusion’s high-performance PDF Library allows you to create PDF documents from scratch without Adobe dependencies.

Conclusion

Thanks for reading! In this blog post, we have learned how to add image and text watermarks in a C# .NET console application using our Syncfusion PDF Library. Try out these methods and leave your feedback in the comments section of this blog post!

In the PDF Library, there are other features such as form authentication, headers, footers, tables of contents, and automatic bookmark hierarchy based on heading style. Take a moment to peruse the documentation, where you’ll find other options and features, all with accompanying code examples.

For existing customers, the new version of Essential Studio is available for download from the License and Downloads page. If you are not a Syncfusion customer, try our 30-day free trial to check out our available features.

For questions, contact us through our support forum, support portal, or feedback portal. We are delighted to assist you!

Related blogs

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed