Watermark PDF (.NET Core/Framework)
Watermark can be added as Text or Image or any other page element to a PDF document.
How to Add Image Watermark to PDF in C#
The ImageWatermark class will be used to add Image Watermark. The following steps and sample code illustrate adding an Image Watermark to PDF document using DynamicPDF Core Suite.
Steps for Adding Image Watermark to a PDF Document
- Create a
Document
object. - Create a
Page
object and add it to the Document instance. - Set the PDF version to v1.6.
- Create a
ImageWatermark
object and provide the path for the Image. - Add
ImageWatermark
to the Page instance. - Save the PDF Document.
Sample Code - C#
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
document.PdfVersion = PdfVersion.v1_6;
ImageWatermark imageWm = new ImageWatermark(imagePath);
page.Elements.Add(imageWm);
document.Draw(@"Output.pdf");
How to Add Text Watermark to PDF in C#
The TextWatermark class is used to add Text as Watermark. The following steps and sample code illustrate adding a Text Watermark to a PDF document using DynamicPDF Core Suite.
Steps for Adding Text Watermark to a PDF Document
- Create a
Document
object. - Create a
Page
object and add it to the Document instance. - Set the PDF version to v1.6.
- Create a
TextWatermark
object and provide a string to be displayed as watermark. - Add the TextWatermark instance to the Page instance.
- Save the PDF Document.
Sample Code - C#
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
document.PdfVersion = PdfVersion.v1_6;
string text = "This is a text watermark.";
TextWatermark twm = new TextWatermark(text);
page.Elements.Add(twm);
document.Draw(@"Output.pdf");
How to Watermark a PDF in C#
An image or text or any other element can be used as a watermark. Any page element can be added by using a Template. The following steps and sample code illustrate adding a watermark to a PDF document using DynamicPDF Core Suite.
Steps for Adding Watermark to a PDF document
- Open the PDF using
MergeDocument
. - Create a watermark template with an
Image
. - Apply the
Template
to the pdf. - Save the watermarked PDF document.
Sample Code - C#
MergeDocument document = new MergeDocument(@"Doc Needs Watermark.pdf");
Image image = new Image(@"Watermark.png", 0, 0);
Template watermarkTemplate = new Template();
watermarkTemplate.Elements.Add(image);
document.Template = watermarkTemplate;
document.Draw(@"Watermarked Output.pdf");
Getting Started
NuGet Package
DynamicPDF Core Suite is available on NuGet and is part of the ceTe.DynamicPDF.CoreSuite.NET
package. The easiest way to install the package is through the Visual Studio Package Manager. You can also download the package directly from NuGet.
DynamicPDF Core Suite Information
More information can be found on the DynamicPDF Core Suite webpage.
Available on Other Platforms
DynamicPDF Core Suite is available for the Java and COM/ActiveX platforms. Refer to the respective product pages for more details.
- Java - DynamicPDF Generator for Java
- COM/ActiveX - DynamicPDF Generator for COM/ActiveX