WatermarkAnnotation Class
A watermark annotation.
Namespace: DevExpress.Docs.Pdf
Assembly: DevExpress.Docs.Pdf.v26.1.dll
NuGet Package: DevExpress.Docs.Pdf
Declaration
Example
How to: Create a Watermark Annotation
The following code snippet creates a diagonal text watermark and add it to a page:

using DevExpress.Docs.Pdf;
using System.Drawing;
using (PdfDocument pdfDocument =
new PdfDocument(File.OpenRead(@"Document.pdf")))
{
// Add the watermark to each page.
foreach (Page page in pdfDocument.Pages)
{
AddTextWatermark(page, "CONFIDENTIAL");
}
// Save the updated document.
pdfDocument.Save(File.OpenWrite(@"DocumentWithWatermark.pdf"));
}
static void AddTextWatermark(Page page, string watermarkText)
{
// Get page boundaries.
RectangleF pageBounds = page.MediaBox;
// Create a reusable form template that defines the watermark appearance.
FormTemplate template = new FormTemplate();
template.Bounds = pageBounds;
// Create and configure the watermark text.
TextFragment fragment = new TextFragment();
fragment.Text = watermarkText;
fragment.Location = new PointF(180, 120);
fragment.RotationAngle = 45;
fragment.Font = new TextFont("Segoe UI");
fragment.FontSize = 72;
fragment.ForegroundFill = new SolidFill(PdfColor.Red, .5);
// Add the text fragment to the template.
template.Fragments.Add(fragment);
// Create a watermark annotation.
WatermarkAnnotation watermark = new WatermarkAnnotation(pageBounds);
// Create the annotation appearance from the template.
AnnotationAppearance appearance = new AnnotationAppearance(template);
// Assign the normal appearance to the annotation.
AnnotationAppearances appearances = new AnnotationAppearances();
appearances.Normal = appearance;
watermark.Appearance = appearances;
// Add the watermark annotation to the page.
page.Annotations.Add(watermark);
}
Implements
Inheritance
Object
BaseAnnotation
WatermarkAnnotation
See Also