// 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>();
// Area annotation with 2 replies
AnnotationInfo areaAnnnotation = new AnnotationInfo();
areaAnnnotation.setAnnotationPosition(new Point(852.0, 59.0));
final AnnotationReplyInfo[] annotationReplyInfos = { new AnnotationReplyInfo() {
{
setMessage("Hello!");
setRepliedOn(Calendar.getInstance().getTime());
setUserName("John");
}
}, new AnnotationReplyInfo() {
{
setMessage("Hi!");
setRepliedOn(Calendar.getInstance().getTime());
setUserName("Judy");
}
} };
areaAnnnotation.setReplies(annotationReplyInfos);
areaAnnnotation.setBackgroundColor(11111111);
areaAnnnotation.setBox(new Rectangle(300f, 200f, 88f, 37f));
areaAnnnotation.setPageNumber(0);
areaAnnnotation.setPenColor(2222222);
areaAnnnotation.setPenStyle((byte) 1);
areaAnnnotation.setPenWidth((byte) 1);
areaAnnnotation.setType(AnnotationType.Area);
areaAnnnotation.setCreatorName("Anonym A.");
annotations.add(areaAnnnotation);
// 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-area.pdf");
IOUtils.copy(result, fileStream);
} catch (Exception e) {
System.out.println("Exception :" + e.getMessage());
e.printStackTrace();
}