karthi
karthi

Reputation: 31

PDFView unable to move to nextpage

Code:

if let path = Bundle.main.path(forResource: "test", ofType: "pdf") {
            let url = URL(fileURLWithPath: path)
            if let pdfDocument = PDFDocument(url: url) {
                pdfView.displayMode = .singlePage
                pdfView.autoScales = true
                pdfView.displayDirection = .horizontal
                pdfView.document = pdfDocument
            }
        }

i try to show pdf file in app.it is working fine.how to implement horizontal scrolling(page by page) and search function(like highlight search word) features.any help will be appericated.thanks in advance

Upvotes: 1

Views: 734

Answers (2)

Jigar
Jigar

Reputation: 1821

try this code for searching string.in this line beginFindString you can set string

var searchedString: PDFSelection?
override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
        self.document?.beginFindString("StringName", withOptions: .caseInsensitive)        
}

func documentDidEndDocumentFind(_ notification: Notification) {
    pdfView.setCurrentSelection(searchedString, animate: true)
}

func documentDidFindMatch(_ notification: Notification) {
    if let selection = notification.userInfo?.first?.value as? PDFSelection {
        selection.color = .Red
        if searchedString == nil {
            // The first found item sets the object.
            searchedString = selection
        } else {
            // All other found selection will be nested
            searchedString!.add(selection)
        }
    }
}

Upvotes: 0

Enea Dume
Enea Dume

Reputation: 3232

you need to add this line of code:

pdfView.usePageViewController(true, withViewOptions: nil)

****UPDATE**

PDFDocument . has some notifications about search. Have a look.

Upvotes: 3

Related Questions