Using the below code to highlight search text string in a pdf.
let selections = pdfView?.document?.findString(searchTerms!, withOptions: [.caseInsensitive])
selections?.forEach { selection in
selection.pages.forEach { page in
let highlight = PDFAnnotation(bounds: selection.bounds(for: page), forType: .highlight, withProperties: nil)
highlight.endLineStyle = .square
highlight.color = #colorLiteral(red: 0.9843137255, green: 0.9019607843, blue: 0.5529411765, alpha: 1)
page.addAnnotation(highlight)
}
}
It works perfectly for small pdfs. But when there are about 2000 or above pages, app freezes. selections take some time. Is there a way to fix this. Tried with delegate for beginDocumentFind also. Same result