I would like to add a button outside the viewer and when the user clicks on it the annotations should be exported to xfdf.
To add a button outside the viewer you could do something like the following in html:
<div>
<label>Annotations:</label>
<input type="button" id="exportAnnotationsButton" value="Export Annotations (as XFDF)"/>
</div>
And then in JavaScript have:
$('#exportAnnotationsButton').click(function() {
var iframeWindow = $('#viewer').find('iframe')[0].contentWindow;
// if you want to get the xfdf string yourself and do something with it then run this
var annotationManager = iframeWindow.readerControl.docViewer.GetAnnotationManager();
var xfdfString = annotationManager.SaveAnnotations();
// if you want to run the logic for saving annotations that is in ReaderControl then do this
// iframeWindow.readerControl.saveAnnotations();
});