In this how-to tutorial, we will walk you through how to add watermark annotation using Java. We will use one of the popular annotation libraries for adding watermark annotation to PDF documents. Further, we will use the process defined in this guide to create a sample code to add watermark annotation in Java. Here are the complete instructions and working example for adding watermark annotation to documents.
Steps to Add Watermark Annotation using Java
- Install GroupDocs.Annotation for Java from the Maven repository for adding watermark annotation
- Import the necessary classes for adding watermark annotation to PDF document
- Create an object of the Annotator class and pass the input PDF file to its constructor
- Initialize WatermarkAnnotation class and define properties for the watermark annotation
- Call the add method of the Annotator class and pass the WatermarkAnnotation object to it
- Call Annotator’s class save method with the resultant document path for saving the output PDF file to the disk
By following the above points in a sequence allows you to easily generate watermark annotation in Java and use it to add to documents. You can start loading the input PDF file by initializing the Annotator class for adding watermark annotation after configuring the project with the required library and importing essential classes. In the next step, instantiate the WatermarkAnnotation class for defining the properties of the watermark annotation. In the end, add watermark annotation and save the resultant document to the disk.
Code to Add Watermark Annotation using Java
We have produced the above sample code to show you the implementation of the Java watermark annotation capability. We have defined many properties for watermark text to create annotation in Java. However, you can further alter these properties for the watermark annotation as per your specific requirements.
We have created a step-by-step guide for adding watermark annotation in Java and produced a sample code for it. We had earlier published tutorial on removing annotation from PDF documents in Java, see how to Remove Annotation from PDF using Java post for more information.