Load Annotations before rendering PDF

Is it possible to load annotations before (or during) rendering of the PDF ?

I have a large PDF that takes 30s to load and then annotations in Xfdf get loaded just after the rendering is finished. Which is a lot of time to wait.

I tried this so far (in Swift), and am a little confused with locks and unlocks, maybe that’s the problem.
Answers in any language are Ok.

`

// OPEN DOCUMENT

ctrl.setProgressiveRendering(true, withInitialDelay: 0, withInterval: 750)
ctrl.setDoc(docToOpen)

//LOCK WRITE PERMISSION
ctrl.getDoc().lock()

// LOAD TOOL MANAGER
self.toolManager = ToolManager(pdfViewCtrl: ctrl)
ctrl.toolDelegate = self.toolManager;
_ = self.toolManager?.changeTool(PanTool.self)

// ANNOTATION TO LOAD IN XFDF
let str : String = “<?xml version=\"1.0\" encoding=\"UTF-8\" ?><xfdf xmlns=“http://ns.adobe.com/xfdf” xml:space=“preserve”><polyline subject=“Polyline” page=“0” rect=“209.407465,97.622084,320.782271,147.821151” flags=“print” name=“55603d93-2c7f-4006-7162-e163257071d5” title=“Guest” date=“D:20171018190626+02’00’” color=”#000000" width=“1” opacity=“1” creationdate=“D:20171018190624+02’00’” head=“None” tail=“None”><popup flags=“print,nozoom,norotate” page=“0” rect=“0,742,150,842” open=“no”/>210.41,98.62;319.78,146.82"

// CREATE AND MERGE THE XFDF TO FDF TO PDF DOC
let fdfDoc : PTFDFDoc = PTFDFDoc.create(fromXFDF: str)
docToOpen?.fdfMerge(fdfDoc)
ctrl.update()

// UNLOCK THE WRITE PERMISSION AND CONTINUE TO RENDER PDF
ctrl.getDoc().unlock()

`

Thanks in advance for your help.

Do you mean 30 seconds to see the first page, or 30 seconds till everything is “loaded”?

How do you instantiate the PDFDoc object?

At the very least, I would move the lock to just surround the fdfmerge. You are locking too soon/long.

let fdfDoc : PTFDFDoc = PTFDFDoc.create(fromXFDF: str) ctrl.docLock() docToOpen?.fdfMerge(fdfDoc) ctrl.update() ctrl.docUnlock()

But I would like to investigate further the 30 seconds issue.

The other alternative, and which might work best for you, is to merge the annotations before opening the document.

let fdfDoc : PTFDFDoc = PTFDFDoc.create(fromXFDF: str) docToOpen?.fdfMerge(fdfDoc) ctrl.setDoc(docToOpen)