Versioning of annotated documents

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 (Annotator annotator = new Annotator("input.pdf")) {
    // Create an instance of AreaAnnotation class and set options
    AreaAnnotation areaAnnotation = new AreaAnnotation();
    areaAnnotation.setBox(new Rectangle(100, 100, 100, 100)); 
    annotator.update(areaAnnotation);
    SaveOptions saveOptions = new SaveOptions();
    saveOptions.setVersion("CUSTOM_VERSION");
    
    // Save to file
    annotator.save("result.pdf", saveOptions);
}
Note
The Version property is object.

Get the list of version keys of a file

To get the list of version keys, call the Annotator.getVersionList() method of the Annotator class.

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 (Annotator annotator = new Annotator("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.

Get the list of annotations using version key

To get the list of annotations in a specific version, call the Annotator.getVersion() method of the Annotator class.

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 (Annotator annotator = new Annotator("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
LoadOptions loadOptions = new LoadOptions();
loadOptions.setVersion("CUSTOM_VERSION");

// Create an instance of Annotator class
try (Annotator annotator = new Annotator("input.pdf", loadOptions)) {
    
    // Save to file
    annotator.save("result_loaded.pdf");
}