How to add watermark on every page of the WinForms PDF document?
The Syncfusion Essential® PDF is a feature-rich and high-performance .NET PDF Library that is 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. Using this library, you can add a watermark on every page of the pdf document.
Steps to add a watermark on every page of the pdf document programmatically
1. Create a new C# console application project.
2. Install the Syncfusion.PDF.WinForms NuGet packages as a reference to your .NET Framework application from NuGet.org.
3. Include the following namespaces in the Program.cs file.
C#
using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Parsing;
VB.NET
Imports Syncfusion.Pdf Imports Syncfusion.Pdf.Graphics Imports Syncfusion.Pdf.Parsing
4. The following code example shows how to add watermark on every page of the pdf document using C#.
C#
//Load the PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("../../Data/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(-40); graphics.DrawString("Imported using Essential PDF", font, PdfPens.Red, PdfBrushes.Red, new PointF(-150, 450)); graphics.Restore(); } //Save and close the document loadedDocument.Save("Watermark.pdf"); loadedDocument.Close(true);
VB.NET
'Load the PDF document Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("../../Data/Barcode.pdf") 'Set the font Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 20) For Each page In loadedDocument.Pages 'Get the loaded page Dim loadedPage As PdfLoadedPage = TryCast(page, PdfLoadedPage) 'Create graphics Dim graphics As PdfGraphics = loadedPage.Graphics Dim state As PdfGraphicsState = graphics.Save() graphics.SetTransparency(0.25F) graphics.RotateTransform(-40) 'Draw watermark text graphics.DrawString("Imported using Essential PDF", font, PdfPens.Red, PdfBrushes.Red, New PointF(-150, 450)) graphics.Restore() Next 'Save and close the document loadedDocument.Save("Watermark.pdf") loadedDocument.Close(True)
A complete working sample can be downloaded from a watermark for every page of the pdf document sample.
By executing the program, you will get the PDF document as follows.
Refer to here to explore the rich set of Syncfusion Essential® PDF features.
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or 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 trail message.
See Also:
https://help.syncfusion.com/file-formats/pdf/working-with-watermarks
https://www.syncfusion.com/kb/9072/how-to-add-watermark-to-pdf-file-in-c-vb-net
https://www.syncfusion.com/kb/9785/how-to-add-a-watermark-to-a-pdf-page-with-an-opaque-image
Conclusion
I hope you enjoyed learning about how to add a watermark on every page of the WinForms PDF document using C#.
You can refer to our WinForms PDF feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms PDF example 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 check out 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, Direct-Trac, or feedback portal. We are always happy to assist you!