[]
        
(Showing Draft Content)

Watermark Annotation

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. GcPdf provides WatermarkAnnotation class to enable the users to apply watermark annotations to the PDF file.

image

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.

type=warning

Note: If both Text and Image properties are specified, then Image property is used as watermark content.

Refer to the following example code to add a watermark annotation to a PDF document:

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");
    }
}