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

85 views
Skip to first unread message

Ryan

unread,
Mar 7, 2017, 4:30:46 PM3/7/17
to PDFTron PDFNet SDK
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.

Martin Lingstuyl

unread,
Dec 20, 2018, 5:44:31 PM12/20/18
to PDFTron PDFNet SDK
Op dinsdag 7 maart 2017 22:30:46 UTC+1 schreef Ryan:
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

Martin Lingstuyl

unread,
Dec 21, 2018, 5:47:33 PM12/21/18
to PDFTron PDFNet SDK
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());
Reply all
Reply to author
Forward
0 new messages