Our Windows Forms DocumentAnnotationViewer is designed in a way to ensure it only loads image and annotation data for the current frame at any given time.
This is a deliberate design choice to ensure that it consumes as little memory as possible - it uses temp files to persist out the rest of the annotations and images for other frames... loading them in as needed.
This means that if you examine documentAnnotationViewer.Annotations.Layers, you will only see one layer no matter how many pages are in the open document, and if you call documentAnnotationViewer.Annotations.Layers.Clear() it will seem to clear the current page but if you navigate away and back they return
To clear the current page's annotations, you can use documentAnnotationViewer.Annotations.CurrentLayer.Items.Clear(); this persists
But to clear all layers you need to actually take a few more steps
The following method is simply passed the DocumentAnnotationViewer object and handles clearing all annotations on all frames
private void ClearAllAnnotations(DocumentAnnotationViewer viewer)
using(AnnotationController ac = new AnnotationController())
for (int i = 0; i < viewer.Count; i++)
using (MemoryStream ms = new MemoryStream())
ac.Save(ms, new XmpFormatter());
viewer.LoadAnnotationData(ms, -1, new XmpFormatter(), true);
The idea is that you create a new blank set of empty layers in an AnnotationController, then serialize that out to a MemoryStream, then load those blank annotations, overwriting what is currently there.
This is FAR more efficient than looping through each frame setting viewer.SelectThumbnail(i); then calling viewer.Annotations.CurrentLayer.Clear();