// 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 replacement annotation
AnnotationInfo textReplacementAnnotation = new AnnotationInfo();
textReplacementAnnotation.setAnnotationPosition(new Point(852.0, 172.0));
textReplacementAnnotation.setFieldText("Replaced text");
textReplacementAnnotation.setFontSize(10);
textReplacementAnnotation.setBox(new Rectangle(68f, 154f, 102f, 9f));
textReplacementAnnotation.setPageNumber(0);
textReplacementAnnotation.setType(AnnotationType.TextReplacement);
textReplacementAnnotation.setCreatorName("Anonym A.");
annotations.add(textReplacementAnnotation);
// 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-textreplacement.pdf");
IOUtils.copy(result, fileStream);
} catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
e.printStackTrace();
}