How do I get the Annotation for the annotation added/edited/deleted callbacks?

Question:

I am using Xamarin.iOS and am unable to identify the annotation in the callbacks from Toolmanager.

`
_toolManager = new pdftron.PDF.Tools.ToolManager(_pdfViewCtrl);
_toolManager.AnnotationAdded += ToolManagerAnnotationAdded;
_toolManager.AnnotationModified += ToolManagerAnnotationModified;
_toolManager.AnnotationRemoved += ToolManagerAnnotationRemoved;

`

Answer:

All three events can be used as follows:

Annot ann = sender as Annot; Annot.Type type = ann.GetType(); Console.WriteLine("Annotation " + which + ": type: " + type + " on page:" + e.PageNumber);

The PDFNetiOSXamarinSample shows an example implementation of this.

Hi,

I'm this, but sender cannot be cast as Annot, it is of the ToolManager type.

this is my code:
_toolManager.AnnotationAdded += _toolManager_AnnotationAdded;
private void _toolManager_AnnotationAdded(object sender, AnnotationModificationEventArgs e)
        {
            Annot annotation = sender as Annot;
            annotation.SetUniqueID(Guid.NewGuid().ToString());
        }

I do have a PTAnnot in the e object, but that cannot be cast to Annot either.

How can this be solved? I need to create a unique id for each annotation.

Kind regards,
Martin
Op dinsdag 7 maart 2017 22:30:46 UTC+1 schreef Ryan:

Question:

I am using Xamarin.iOS and am unable to identify the annotation in the callbacks from Toolmanager.

_toolManager = new pdftron.PDF.Tools.ToolManager(_pdfViewCtrl);
_toolManager.AnnotationAdded += ToolManagerAnnotationAdded;
_toolManager.AnnotationModified += ToolManagerAnnotationModified;
_toolManager.AnnotationRemoved += ToolManagerAnnotationRemoved;

Answer:

All three events can be used as follows:

Annot ann = sender as Annot;
Annot.Type type = ann.GetType();
Console.WriteLine("Annotation " + which + ": type: " + type + " on page:" + e.PageNumber);

The PDFNetiOSXamarinSample shows an example implementation of this.

For anyone searching for the solution: this is the answer:

I was trying to set a unique ID on the annotation within Xamarin/IOS.

The _toolManager_AnnotationAdded event returned a PTAnnot object, on which I could not run a function in C#. I had to convert it to Annot object using the TypeConvertHelper.

var annotation = TypeConvertHelper.ConvAnnotToManaged(e.Annotation);

After this I could use its functions:
annotation.SetUniqueID(Guid.NewGuid().ToString());