// 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 field annotation
AnnotationInfo textFieldAnnotation = new AnnotationInfo();
textFieldAnnotation.setAnnotationPosition(new Point(852.0, 201.0));
textFieldAnnotation.setFieldText("text in the box");
textFieldAnnotation.setFontFamily("Arial");
textFieldAnnotation.setFontSize(10);
textFieldAnnotation.setBox(new Rectangle(66f, 201f, 64f, 37f));
textFieldAnnotation.setPageNumber(0);
textFieldAnnotation.setType(AnnotationType.TextField);
textFieldAnnotation.setCreatorName("Anonym A.");
annotations.add(textFieldAnnotation);
// 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-textfield.pdf");
IOUtils.copy(result, fileStream);
} catch (Exception e) {
System.out.println("Exception :" + e.getMessage());
e.printStackTrace();
}