Watermark PDF
Add watermarks as text, an image, or any other page element to a PDF document using DynamicPDF Core Suite.
How to Add Image Watermark to PDF in C#
The ImageWatermark
class adds an Image Watermark to a PDF. The following steps and sample code illustrate adding an image watermark to a 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 theDocument
instance. - Set the PDF version to v1.6.
- Create a
ImageWatermark
object and provide the path for the image. - Add the
ImageWatermark
object to thePage
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 adds Text as a watermark to a PDF. 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 theDocument
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 thePage
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, text, or any other element can be used as a watermark. Use a Template
to add any page element as a watermark. The following steps and sample code illustrate adding a watermark using a Template
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");
GitHub Project
Clone or view the example project at GitHub. This example code is contained in the Examples/WatermarkExample.cs file.
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
DynamicPDF Core Suite contains over 75 page elements so you can add rich content to the PDFs you create:
- Images
- Text Objects (TextArea and Label)
- HTML
- Barcodes (47 types)
- Form Fields
- Charts
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