// 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);
InputStream cleanDoc = new FileInputStream(Utilities.storagePath + File.separator + fileName);
List<AnnotationInfo> annotations = new ArrayList<AnnotationInfo>();
// init text replacement annotations
AnnotationInfo textReplacementAnnotation = new AnnotationInfo();
textReplacementAnnotation.setFieldText(" \"REPLACED TEXT\" ");
textReplacementAnnotation.setFontSize(10);
textReplacementAnnotation.setSvgPath(
"[{\"x\":251.224,\"y\":637.20401},{\"x\":327.89,\"y\":637.20401},{\"x\":251.224,\"y\":628.20401},{\"x\":327.89,\"y\":628.20401}]");
textReplacementAnnotation.setPageNumber(1);
textReplacementAnnotation.setType(AnnotationType.TextReplacement);
annotations.add(textReplacementAnnotation);
// Add annotation to the document
InputStream result = annotator.exportAnnotationsToDocument(cleanDoc, annotations, DocumentType.Words);
// Save result stream to file.
OutputStream fileStream = new FileOutputStream(
Utilities.outputPath + File.separator + "words-annotated.docx");
System.out.println(result.available());
IOUtils.copy(result, fileStream);
} catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
e.printStackTrace();
}