Versioning of annotated documents

Every time you are saving file using Annotator.Save() method - you implicitly create a new version of the annotated file. Versions list stores not document, it keeps annotations that you add, remove, and change. So you can easy swap between different changes made with GroupDocs.Annotation. And of course you can set your version names.

By default, they are created using unique GUID keys. Next, each aspect of using versions will be considered. The API execution logic has not changed, so you do not need to change your code to use it as before. The latest version of document is loaded by default. 

Backward Compatibility

The update is fully compatible with previous and next updates (The latest saved version will be used), however, using versions on previous versions is not possible and the list of versions in this document will not be changed. And If you update file from 20.4+ using 20.2 and lower few times, after loading this document on 20.4+ only last changes will be added as new version.

Add Version with custom name

If you want to swap between versions easily you might need to have ability to set custom versions names.

Here the code that demonstrates how to save version with custom name:

using (Annotator annotator = new Annotator("input.pdf"))
	annotator.Update(new AreaAnnotation{ Box = new Rectangle(100, 100, 100, 100) });
	annotator.Save("result.pdf", new SaveOptions { Version = "CUSTOM_VERSION" });

Get List of All version keys on a document

If you don’t know what versions were added earlier or want to know versions count  Here the code that demonstrates how to get list of versions keys, you could do this calling GetVersionsList method of Annotator:

using (Annotator annotator = new Annotator("result.pdf")) { 
      List<object> versionKeys = annotator.GetVersionsList();

Get List of Annotations using version key

If you need to get list of annotations you can use Annotator.GetVersion() method Here code that demonstrates how to get list of annotations from specific version of document

using (Annotator annotator = new Annotator("result.pdf"))
    List<AnnotationBase> annotations = annotator.GetVersion("CUSTOM_VERSION");

Load Document of custom Version

Using LoadOptions.Version property you could load specific version of annotated document Here the code that demonstrates how load version using version property:

 using (Annotator annotator = new Annotator($"result.{ext}", new LoadOptions { Version = "CUSTOM_VERSION" }))

More resources

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online App

Along with full-featured .NET library we provide simple but powerful free Apps. You are welcome to annotate your PDF, DOC or DOCX, XLS or XLSX, PPT or PPTX, PNG and other documents with free to use online GroupDocs Annotation App.