// 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>();
// text annotation
AnnotationInfo textAnnotation = new AnnotationInfo();
textAnnotation.setBox(new Rectangle(68, 154, 102, 9));
textAnnotation.setPageNumber(0);
textAnnotation.setType(AnnotationType.Text);
textAnnotation.setCreatorName("Anonym A.");
annotations.add(textAnnotation);
// 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-text.pdf");
IOUtils.copy(result, fileStream);
} catch (Exception e) {
System.out.println("Exception :" + e.getMessage());
e.printStackTrace();
}