The Syncfusion .NET PDF Library provides support to add watermark as an image or text that is added 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 specifying the position, size, and opacity of the watermark.
Name | Description |
---|---|
Text watermark | It a practical technique for maintaining document security, intellectual property protection, and branding initiatives. |
Image watermark | It can be a useful tool for protecting your intellectual property, establishing your brand identity, adding security features to your documents, and indicating confidentiality. |
Remove watermark | It can be useful in cases where the watermark is no longer needed, or when the PDF file needs to be shared without the watermark. |
Text watermarks are a practical technique for maintaining document security, intellectual property protection, and branding initiatives. Yet, it can act as a deterrent and aid in identifying the document's owner or origin.
The following code example shows how to create text watermark in 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 watermark in PDF document like in the following screenshot.
Image watermarks can be a useful tool for protecting your intellectual property, establishing your brand identity, adding security features to your documents, and indicating confidentiality.
The following code example shows how to create an image watermark in 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 watermark in PDF document like in the following screenshot.
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.
The following code example shows how to remove a watermark in PDF document 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 get a remove watermark in PDF document like in the following screenshot.
- Download this project to a location in your disk.
- Open the solution file using Visual Studio.
- Rebuild the solution to install the required NuGet package.
- Run the application.
- Product page: Syncfusion PDF Framework
- Documentation page: Syncfusion .NET PDF library
- Online demo: Syncfusion .NET PDF library - Online demos
- Blog: Syncfusion .NET PDF library - Blog
- Knowledge Base: Syncfusion .NET PDF library - Knowledge Base
- EBooks: Syncfusion .NET PDF library - EBooks
- FAQ: Syncfusion .NET PDF library - FAQ
- For any other queries, reach our Syncfusion support team or post the queries through the community forums.
- Request new feature through Syncfusion feedback portal.
This is a commercial product and requires a paid license for possession or use. Syncfusion’s licensed software, including this component, is subject to the terms and conditions of Syncfusion's EULA. You can purchase a licnense here or start a free 30-day trial here.
Founded in 2001 and headquartered in Research Triangle Park, N.C., Syncfusion has more than 26,000+ customers and more than 1 million users, including large financial institutions, Fortune 500 companies, and global IT consultancies.
Today, we provide 1600+ components and frameworks for web (Blazor, ASP.NET Core, ASP.NET MVC, ASP.NET WebForms, JavaScript, Angular, React, Vue, and Flutter), mobile (Xamarin, Flutter, UWP, and JavaScript), and desktop development (WinForms, WPF, WinUI(Preview), Flutter and UWP). We provide ready-to-deploy enterprise software for dashboards, reports, data integration, and big data processing. Many customers have saved millions in licensing fees by deploying our software.