A watermark annotation defines graphics that is expected to be printed at a fixed size and position on a page, regardless of the dimensions of the printed page. DsPdf provides WatermarkAnnotation class to enable the users to apply watermark annotations to the PDF file.
WatermarkAnnotation class provides the following properties to set various options for the watermark annotation:
Property | Description |
---|---|
HorzTranslate | Sets the amount to translate the associated content horizontally as a percentage of the width of the target media (or, if unknown, the width of the page’s MediaBox). 1.0 represents 100%, and 0.0 represents 0%. Negative values are not recommended since they may cause content to be drawn off the page. |
Image | Sets the image for watermark annotation. |
Text | Sets the text for watermark annotation. |
TextFormat | Sets the formatting of the annotation's text. |
VertTranslate | Sets the amount to translate the associated content vertically as a percentage of the height of the target media (or, if unknown, the height of the page’s MediaBox). 1.0 represents 100%, and 0.0 represents 0%. Negative values are not recommended since they may cause content to be drawn off the page. |
Refer to the following example code to add a watermark annotation to a PDF document:
C# |
Copy Code
|
---|---|
public void CreateWatermarkAnnotation() { GcPdfDocument doc = new GcPdfDocument(); var fs = new FileStream(Path.Combine("CompleteJavaScriptBook.pdf"), FileMode.Open, FileAccess.Read); doc.Load(fs); //Load the document //Loop over pages, add a watermark to each page: foreach (var page in doc.Pages) { //Create an instance of WatermarkAnnotation class and set its relevant properties var watermark = new WatermarkAnnotation() { PdfRect = new RectangleF(50, 300, 500, 150), Image = Image.FromFile("draft-copy.png"), Page = page // Add watermark to page }; doc.Save("WatermarkAnnotation.pdf"); } } |