How to access annotation from PTVectorAnnot

Product: PDFtron Demo

Please give a brief summary of your issue:
→ How to get annotation from PTVectorAnnot
→ App is crashing if we access second time

Steps to reproduce:
→ Load given PDF and Merge XFDF also
→ call below function and app will crash on last line.

//Iterate loop over all pages to get all annotations
var TotalAnnotoations = [PTAnnot]()
(1...documentController.pdfViewCtrl.pageCount).forEach({index in
     let annotations = documentController.pdfViewCtrl.getAnnotationsOnPage(index).filter({ $0.isValid() && $0.isMarkup()})
     TotalAnnotoations.append(contentsOf: annotations)

//Adding all annotations in PTVectorAnnot
let ptAnnotVector = PTVectorAnnot()        
TotalAnnotoations.forEach { annot in
//Trying to get first PTAnnot from first index of PTVectorAnnot
let a = ptAnnotVector?.get(0).getUniqueIDAsString()
let b = ptAnnotVector?.get(0).getUniqueIDAsString() //When trying again App Crashes

(App is also crashed if we use “get” func first time from PTVectorAnnot and then we use func FDFExtractCommand: )

Sample File: PDF1.pdf (164.1 KB)
Sample XFDF: xfdf.xml (23.1 KB)

Can you please tell us what we are doing wrong? and how can we use this. Proper documentation was not there.

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:


Hi there,

Does the app crash if you do not call any methods on the PTVectorAnnot instance before passing it into the -[PTPDFDoc FfDFExtractCommand:] method?

Hi @dluco ,

No, If we do not call any other method before [PTPDFDoc FfDFExtractCommand:] it is not crashing.
But if we iterate loop over PTVectorAnnot object with get function and then call FfDFExtractCommand function, app is getting crash.

We will look into why a crash would occur if the get() function is called. However, you can avoid the crash by simply not calling the function.

If you need to store, loop over, and operate on a list of annotations, you can use a normal Swift Array or NSArray object.

Hi @dluco ,
Thanks, Yes we are doing same now. Using array solved our purpose.