// For complete examples and data files, please go to https://github.com/groupdocs-annotation/GroupDocs.Annotation-for-Java
try {
AnnotationConfig cfg = Utilities.getConfiguration();
AnnotationImageHandler annotator = new AnnotationImageHandler(cfg);
annotator.getDocumentDataHandler();
InputStream cleanPdf = new FileInputStream(Utilities.storagePath + File.separator + fileName);
List<AnnotationInfo> annotations = new ArrayList<AnnotationInfo>();
// Watermark annotation
AnnotationInfo watermarkAnnotation = new AnnotationInfo();
watermarkAnnotation.setAnnotationPosition(new Point(852.0, 300.0));
watermarkAnnotation.setFieldText("TEXT STAMP");
watermarkAnnotation.setFontFamily("Microsoft Sans Serif");
watermarkAnnotation.setFontSize(10);
watermarkAnnotation.setFontColor(2222222);
watermarkAnnotation.setBox(new Rectangle(430f, 272f, 66f, 51f));
watermarkAnnotation.setPageNumber(0);
watermarkAnnotation.setType(AnnotationType.TextField);
watermarkAnnotation.setCreatorName("Anonym A.");
annotations.add(watermarkAnnotation);
// Add annotation to the document
InputStream result = annotator.exportAnnotationsToDocument(cleanPdf, annotations, DocumentType.Pdf);
// Save result stream to file.
OutputStream fileStream = new FileOutputStream(
Utilities.outputPath + File.separator + "annotated-watermark.pdf");
IOUtils.copy(result, fileStream);
} catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
e.printStackTrace();
}