0

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

iosdev
  • 5
  • 2
  • Have you tested wether the finding or the annotating is the issue? – nOk Oct 22 '21 at 20:40
  • findString will take so long...it depends on page number...if number of pages are more...delay will also be more – iosdev Oct 25 '21 at 04:37

0 Answers0