Watermarks
The DynamicPDF Core Suite for .NET supports adding image and text watermarks to PDF page through the ImageWatermark and TextWatermark classes. These classes allow placing watermark on a page or to all pages in a template.
Watermark
The ImageWatermark
and TextWatermark
classes are children of the Watermark class. The Watermark
class has properties for setting a watermark's Angle, Opacity, Position, and numerous other properties.
ImageWatermark
Add image watermarks to a page using the ImageWatermark class. Add the watermark to a single page or multiple pages using a template.
Page Example
Add a watermark to a single page by adding the watermark directly to the page's page elements.
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
ImageWatermark imageWm = new ImageWatermark(imagePath);
page.Elements.Add(imageWm);
document.Draw("output.pdf");
Dim document As New Document()
Dim page As New Page()
document.Pages.Add(page)
Dim imageWm As New ImageWatermark("Resources/Images/large-logo.png")
imageWm.ScaleX = 0.75F
imageWm.ScaleY = 0.75F
page.Elements.Add(imageWm)
document.Draw("output.pdf"))
Figure 1. A PDF page with an image watermark.
Template Example
Add an image watermark to a document as a whole, or to sections using a template.
Document document = new Document();
document.Pages.Add(new Page(PageSize.Letter));
document.Pages.Add(new Page(PageSize.Letter));
Image image = new Image("stamp.png", 0, 0);
Template watermarkTemplate = new Template();
watermarkTemplate.Elements.Add(image);
document.Template = watermarkTemplate;
document.Draw("output.pdf");
Dim document As New Document()
document.Pages.Add(New Page(PageSize.Letter))
document.Pages.Add(New Page(PageSize.Letter))
Dim image As New Image("stamp.png", 0, 0)
Dim watermarkTemplate As New Template()
watermarkTemplate.Elements.Add(image)
document.Template = watermarkTemplate
document.Draw("output.pdf")
Figure 2. A PDF with an image watermark.
TextWatermark
Add text watermarks to a page using the TextWatermark class. Add the watermark to a single page or multiple pages using a template (see example above).
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
string text = "This is a text watermark.";
TextWatermark twm = new TextWatermark(text);
page.Elements.Add(twm);
document.Draw("Output.pdf");
Dim document As New Document()
Dim page As New Page()
document.Pages.Add(page)
Dim text As String = "This is a text watermark."
Dim twm As New TextWatermark(text)
page.Elements.Add(twm)
document.Draw("output.pdf")
Figure 3. A PDF page with a text watermark.