Watermarks are one of the ways to add security to your documents that contain highly confidential information or can be used to verify if a PDF document is a copy or original, or from the authorized company. These are similar to stamps but cannot be moved or changed like stamps. For more information on watermarks, see PDF specification 2.0 (Section 12.5.6.22).
DsPdf library provides easy mechanism to add watermarks to your PDF documents with WatermarkAnnotation class and provides additional properties to enhance them.
To add a watermark in a PDF document, use the WatermarkAnnotation class. The WaterMarkAnnotation class provides the essential properties for creating an image based watermark.
To add a watermark:
C# |
Copy Code
|
---|---|
public void CreatePDF(Stream stream) { GcPdfDocument doc = new GcPdfDocument(); var page = doc.NewPage(); var g = page.Graphics; TextFormat tf = new TextFormat() { Font = StandardFonts.HelveticaBold, FontSize = 72 }; var watermark = new WatermarkAnnotation() { Name = "WaterMark Sample", Image = Image.FromFile(@ "puffins.jpg"), Rect = new RectangleF(100.5F, 110.5F, 500, 250), TextFormat = tf, Text = "DraftCopy", }; // Add watermark to page page.Annotations.Add(watermark); doc.Save(stream); } |