1

代码:

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
            }
        }

我尝试在应用程序中显示 pdf 文件。它工作正常。如何实现水平滚动(逐页)和搜索功能(如突出显示搜索词)功能。任何帮助都将得到应用。提前感谢

4

2 回答 2

3

你需要添加这行代码:

pdfView.usePageViewController(true, withViewOptions: nil)

****更新**

PDF文档. 有一些关于搜索的通知。看一看。

于 2018-06-29T12:32:21.860 回答
0

尝试使用此代码搜索字符串。在此行 beginFindString 中您可以设置字符串

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)
        }
    }
}
于 2018-06-29T12:51:11.583 回答