Articles in this section
Category / Section

How to add multiple watermarks in PDF document using C# and VB.NET?

5 mins read

 

The Syncfusion Essential® PDF is a feature rich and high-performance .NET PDF library used to create, read, and edit PDF documents programmatically without Adobe dependencies. This library also offers functionality to merge, split, stamp, forms, compress, and secure PDF files.

You can add multiple watermarks in a PDF document using this library.

 

Steps to add multiple Watermark in PDF document using C# and VB.Net:

  1. Create a new C# console application project.

 

Create a console c# application

 

  1. Install the Syncfusion.Pdf.WinForms NuGet package as a reference to your .NET standard applications from NuGet.org.

Install the Syncfusion winforms NuGet

 

  1. Include the following namespaces in Form.cs file:

 

      C#:

using Syncfusion.Pdf;
       using Syncfusion.Pdf.Parsing;

 

             VB.Net:

Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Parsing

 

 

  1. Include the following namespaces in the Program.cs file:

 

C#:

//Load the PDF document
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Barcode.pdf");
 
//Set the font
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
 
foreach (var page in loadedDocument.Pages)
{
//Get the loaded page
PdfLoadedPage loadedPage = page as PdfLoadedPage;
//Create graphics 
PdfGraphics graphics = loadedPage.Graphics;
 
//Draw watermark text
PdfGraphicsState state = graphics.Save();
graphics.SetTransparency(0.25f);
graphics.RotateTransform(-80);
int y = 100;
for (int i = 0; i < 4; i++)
{
graphics.DrawString("WaterMark", font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, y));
graphics.DrawString("WaterMark", font, PdfPens.Red, PdfBrushes.Red, new PointF(-300, y));
y = y + 100;
}
graphics.Restore();
}
 
//Save and close the document
loadedDocument.Save("Watermark.pdf");
loadedDocument.Close(true);
 

 

             VB.Net:

Private Sub SurroundingSub()
  Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("Barcode.pdf")
        Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 20)
 
        For Each page In loadedDocument.Pages
            Dim loadedPage As PdfLoadedPage = TryCast(page, PdfLoadedPage)
            Dim graphics As PdfGraphics = loadedPage.Graphics
            Dim state As PdfGraphicsState = graphics.Save()
            graphics.SetTransparency(0.25F)
            graphics.RotateTransform(-80)
            Dim y As Integer = 100
 
            For i As Integer = 0 To 4 - 1
                graphics.DrawString("WaterMark", font, PdfPens.Red, PdfBrushes.Red, New PointF(-150, y))
                graphics.DrawString("WaterMark", font, PdfPens.Red, PdfBrushes.Red, New PointF(-300, y))
                y = y + 100
            Next
 
            graphics.Restore()
        Next
 
        loadedDocument.Save("Watermark.pdf")
        loadedDocument.Close(True)
End Sub

 

  1. By executing the program, you will get the PDF document as follows:

 

Output pdf window

 

A complete working sample can be downloaded from WatermarkSample.zip

 

Take a moment to peruse the documentation, where you can find the options like adding text and image watermark to the PDF document.

 

Refer here to explore the rich set of Syncfusion Essential® PDF features.


 

Note:

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.

 

Conclusion:

I hope you enjoyed learning about how to add multiple watermarks in PDF document using C# and VB.NET.

 

You can refer to our Flutter PDF feature tour page to learn about its other groundbreaking features and documentation, and how to quickly get started with configuration specifications. You can also explore our Flutter PDF Flutter PDF examples to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to explore our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums or feedback portal. We are always happy to assist you!

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied