Add watermark annotation

On this page

Watermark annotation adds text watermark as shown in the picture below:

You can specify the following properties of the WatermarkAnnotation class:

  • Box defines the annotation position at the document page
  • Text defines the watermark text
  • FontColor defines the color of the annotation text
  • FontFamily defines the font of the annotation text
  • FontSize defines the text font size. If the AutoScale property is true, GroupDocs.Annotation ignores this property
  • Opacity allows you to set the annotation opacity
  • Angle defines the watermark text angle
  • VerticalAlignment defines the vertical alignment
  • HorizontalAlignment defines the horizontal alignment
  • AutoScale sets the watermark size depending on the word length and the page size. If this property is true, GroupDocs.Annotation ignores the FontSize property

To add a watermark annotation, follow these steps:

  1. Instantiate the Annotator class. Specify the input document path or stream.
  2. Instantiate the WatermarkAnnotation class. Specify the appropriate properties (position, page number, etc).
  3. Call the Add method. Specify the WatermarkAnnotation class.
  4. Call the Save method. Specify the output document path or stream.

The following code snippet shows demonstrates how to add WatermarkAnnotation to the document:

//Add watermark annotation to the document from local disk
using (Annotator annotator = new Annotator("input.pdf"))
{
	WatermarkAnnotation watermark = new WatermarkAnnotation
    {
    	Angle = 75,
        Box = new Rectangle(200, 200, 100, 50),
        CreatedOn = DateTime.Now,
        Text = "Watermark",
        FontColor = 65535,
        FontSize = 12,
        Message = "This is watermark annotation",
        Opacity = 0.7,
        AutoScale = true,
        HorizontalAlignment = HorizontalAlignment.Center,
        VerticalAlignment = VerticalAlignment.Center,
        Replies = new List<Reply>
        {
        	new Reply
            {
            	Comment = "First comment",
                RepliedOn = DateTime.Now
            },
            new Reply
            {
            	Comment = "Second comment",
                RepliedOn = DateTime.Now
            }
        }
    };
    annotator.Add(watermark);
    annotator.Save("result.pdf");
} 
.

On this page