Here are the key reasons to use the new updated API provided by GroupDocs.Annotation for Java since version 19.8:
The Annotator class introduced as a single entry point to manage the document annotating process to any supported file format (instead of AnnotationImageHandler class in previous versions).
The overall rendering speed improved dramatically by saving rendered page as soon as it was rendered, not when all pages list were rendered.
Document saving options simplified so it is easy to instantiate proper options class and to control over document annotating and saving processes.
How to migrate?
Here is a brief comparison of how to annotate document and save it using old and new API.
Old coding style
List<AnnotationInfo>annotations=newList<AnnotationInfo>();AnnotationInfoareaAnnotation=newAnnotationInfo();areaAnnotation.setPageNumber(0);areaAnnotation.setBox(newRectangle(100,100,100,100));areaAnnotation.setType(Domain.AnnotationType.Area);areaAnnotation.setText("area");AnnotationInfoellipseAnnotation=newAnnotationInfo();ellipseAnnotation.setPageNumber(0);ellipseAnnotation.setBox(newRectangle(200,200,80,80));ellipseAnnotation.setType(Domain.AnnotationType.Ellipse);ellipseAnnotation.setText("ellipse");// Create annotation config
AnnotationConfigconfig=newAnnotationConfig();// Set storage path
config.setStoragePath("storage");// Create annotation handler
AnnotationImageHandlerannotator=newAnnotationImageHandler(config);// Create input file
// Export annotations and save result
InputStreamresult=annotator.exportAnnotationsToDocument(fs,annotations);// Save result stream to file.
OutputStreamfileStream=newFileOutputStream("input.pdf");IOUtils.copy(result,fileStream);
New coding style
// Create list of annotations
List<AnnotationBase>annotations=newList<AnnotationBase>();AreaAnnotationareaAnnotation=newAreaAnnotation();areaAnnotation.setPageNumber(0);areaAnnotation.setBox(newRectangle(100,100,100,100));areaAnnotation.setText("area");EllipseAnnotationellipseAnnotation=newEllipseAnnotation();ellipseAnnotation.setPageNumber(0);ellipseAnnotation.setBox(newRectangle(200,200,80,80));ellipseAnnotation.setText("ellipse");Annotatorannotator=newAnnotator("input.pdf");// Add annotations
annotator.Add(annotations);// Save result to "result.pdf"
annotator.Save("result.pdf",newSaveOptions());