XDoc.PDF
Features
Tech Specs
How-to C#
How-to VB.NET
Pricing
C# PDF: How to PDF Create PDF Export File and Page Process PDF Read PDF Write Form Process Document Protect Annotation & Drawing PDF Print WPF Viewer & Editor Work with Other SDKs Barcode Read Barcode Create OCR Twain
Page: Add Watermark to PDF
  |  
Home ›› XDoc.PDF ›› C# PDF: Add Watermark to PDF

C#.NET PDF Library - Add/Remove Watermark to PDF Page


An Excellent PDF Control Allows C# Developers to add or delete watermark to PDF File in C#.NET



Look for HTML5 PDF Editor?

EdgePDF: ASP.NET PDF Editor is the best HTML5 PDF Editor and ASP.NET PDF Viewer based on XDoc.PDF, JQuery, HTML5. It supports ASP.NET MVC and WebForms projects.


Professional PDF SDK for Visual Studio .NET, which able to add watermark in C#.NET class


Advanced PDF edit control and component for modify watermark in both C#.NET WinForms


Free online sample code for quick evaluation in Visual C#.NET framework for PDF watermark


Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint


Easy to add/remove watermark to/from PDF page online in browser in ASP.NET web project


Support to copy a PDF watermark to another PDF file page in .NET framework


Support to add different watermark to PDF file.






C# apply page watermark settings to a PDF document object





String inputFilePath = Program.RootPath + "\\" + "1.pdf";
String outputFilePath = Program.RootPath + "\\" + "1_watermk.pdf";

//  open a PDF file
PDFDocument doc = new PDFDocument(inputFilePath);

PDFWatermarkTextRes resWatermark = new PDFWatermarkTextRes("Confidential", new Font("Arial", 72F, FontStyle.Regular), Color.Black, WatermarkTextAlignment.Center);

{
    //  define a watermark setting
    PDFPageWatermark watermark1 = new PDFPageWatermark(resWatermark);
    watermark1.IsAbovePage = false;
    watermark1.Rotate = -45F;
    watermark1.Opacity = 0.2F;

    //  define page range: all odd pages
    PageRangeOptions pageRange1 = new PageRangeOptions();
    pageRange1.AllPages = true;
    pageRange1.Subset = PageRangeSubset.Odd;

    //  apply watermark settings to all odd pages
    PDFPageFieldHandler.ApplyWatermark(doc, watermark1, pageRange1);
}
{
    //  define a watermark setting
    PDFPageWatermark watermark2 = new PDFPageWatermark(resWatermark);
    watermark2.IsAbovePage = false;
    watermark2.Rotate = 45F;
    watermark2.Opacity = 0.2F;

    //  define page range: all even pages
    PageRangeOptions pageRange2 = new PageRangeOptions();
    pageRange2.AllPages = true;
    pageRange2.Subset = PageRangeSubset.Even;

    //  apply watermark settings to all even pages
    PDFPageFieldHandler.ApplyWatermark(doc, watermark2, pageRange2);
}

doc.Save(outputFilePath);




C# remove all page watermark settings in a PDF document object





String inputFilePath = Program.RootPath + "\\" + "1_watermk.pdf";
String outputFilePath = Program.RootPath + "\\" + "output.pdf";

PDFDocument doc = new PDFDocument(inputFilePath);
PDFPageFieldHandler.RemoveWatermarks(doc);
doc.Save(outputFilePath);




C# retrieve all page watermark settings from a PDF file





String inputFilePath = Program.RootPath + "\\" + "1_watermk.pdf";

PDFDocument doc = new PDFDocument(inputFilePath);

//  get all Watermark settings in the document
PDFPageWatermarkInfo info = PDFPageFieldHandler.RetreiveWatermarks(doc);

//  get default setting for Watermark and Page Range
PDFPageWatermark defaultSetting = info.GetDefaultSetting();
PageRangeOptions defaultPageRange = info.GetDefaultPageRangeSettings();




C#.NET: Watermark Property Settings



If you want to display the watermark with different effects, you can set the effects with following properties: