// 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 Field annotations
AnnotationInfo textFieldAnnotation = new AnnotationInfo();
textFieldAnnotation.setFieldText("text in the box");
textFieldAnnotation.setFontFamily("Arial");
textFieldAnnotation.setFontSize(10);
textFieldAnnotation.setBox(new Rectangle(92f, 73f, 106f, 45f));
textFieldAnnotation.setPageNumber(1);
textFieldAnnotation.setType(AnnotationType.TextField);
annotations.add(textFieldAnnotation);
// 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();
}