When you save a file using the Annotator.save() method, the GroupDocs.Annotations creates a version of the annotated file. Versions list keeps annotations that you add, remove, and change. You can swap between different changes made with GroupDocs.Annotation. If needed, you can set your version names.
By default, GroupDocs.Annotations names version using a GUID. You can specify a custom version name.
Add version with custom name
You can specify a custom version name.
The following code snippet shows how to save version with custom name:
// This example demonstrates how to add version.
// Create an instance of Annotator class
try(Annotatorannotator=newAnnotator("input.pdf")){// Create an instance of AreaAnnotation class and set options
AreaAnnotationareaAnnotation=newAreaAnnotation();areaAnnotation.setBox(newRectangle(100,100,100,100));annotator.update(areaAnnotation);SaveOptionssaveOptions=newSaveOptions();saveOptions.setVersion("CUSTOM_VERSION");// Save to file
annotator.save("result.pdf",saveOptions);}
The following code snippet shows how to get list of versions keys:
// This example demonstrates how to get list of all version keys on a document.
// Create an instance of Annotator class
try(Annotatorannotator=newAnnotator("input.pdf")){// Get versions lest from annotated file
List<Object>versionKeys=annotator.getVersionsList();}
Note
The Annotator.GetVersionList() method returns list of objects. If needed, you can convert them to appropriate type.
The following code snippets shows how to get list of annotations in a specific version:
// This example demonstrates how get list of annotations using version key.
// Create an instance of Annotator class
try(Annotatorannotator=newAnnotator("input.pdf")){// Get versions lest from annotated file by CUSTOM_VERSION
List<AnnotationBase>annotations=annotator.getVersion("CUSTOM_VERSION");}
Note
The Annotator.getVersion method returns list of objects. If needed, you can convert them to appropriate type.
Load a specific file version
To load a specific version of a file, call the LoadOptions.version() method and specify the version key.
The following code snippets shows how load version using version property:
// This example demonstrates how to load document of custom version.
// Create an instance of Annotator class and set custom version
LoadOptionsloadOptions=newLoadOptions();loadOptions.setVersion("CUSTOM_VERSION");// Create an instance of Annotator class
try(Annotatorannotator=newAnnotator("input.pdf",loadOptions)){// Save to file
annotator.save("result_loaded.pdf");}
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.