【问题标题】:PDFView unable to move to nextpagePDFView 无法移至下一页
【发布时间】:2018-12-08 15:29:56
【问题描述】:

代码:

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 文件。它工作正常。如何实现水平滚动(逐页)和搜索功能(如突出显示搜索词)功能。任何帮助都将得到应用。提前感谢

【问题讨论】:

    标签: ios swift pdf ios-pdfkit


    【解决方案1】:

    你需要添加这行代码:

    pdfView.usePageViewController(true, withViewOptions: nil)
    

    ****更新**

    PDFDocument 。有一些关于搜索的通知。看看吧。

    【讨论】:

    • 谢谢它运行良好。抱歉,我没有足够的声誉来支持你。关于搜索功能有什么想法吗?
    • 搜索功能是什么意思?
    • 喜欢移动到特定页面或突出显示匹配的单词,如 word 文档
    【解决方案2】:

    尝试使用此代码搜索字符串。在此行 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)
            }
        }
    }
    

    【讨论】:

    • 这里的 searchedItem 是什么?
    • 将 searchedItem 更改为 searchedString
    • documentDidEndDocument,documentDidFindMatch 方法没有被调用
    • 请委托您的 pdfview
    • 需要设置pdfview.delegate = self吗?
    猜你喜欢
    • 2021-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-29
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多