【问题标题】:How to highlight selected text in pdf using PDFKit?如何使用 PDFKit 突出显示 pdf 中的选定文本?
【发布时间】:2019-11-13 14:08:36
【问题描述】:

我已经设置了一个 PDFViewer,并想添加一个突出显示功能,以便当用户选择文本时,他们可以突出显示它。当您在笔记、iMessages 等中突出显示文本时,您可以选择全选、复制、粘贴等。您将如何编辑它以便同时拥有突出显示功能?此外,应用程序如何保存突出显示,以便当用户关闭并重新打开应用程序时,他们仍然能够查看突出显示的文本?这会涉及使用核心数据还是其他东西?谢谢!

this is a screenshot of the default functionalities that Apple provides but I would like to add an additional highlighting functionality

【问题讨论】:

    标签: ios swift highlight ios-pdfkit apple-pdfkit


    【解决方案1】:
    let select = pdfView.currentSelection?.selectionsByLine()
        //assuming for single-page pdf.
        guard let page = select?.first?.pages.first else { return }
    
        select?.forEach({ selection in
            let highlight = PDFAnnotation(bounds: select.bounds(for: page), forType: .highlight, withProperties: nil)
            highlight.endLineStyle = .square
            highlight.color = UIColor.orange.withAlphaComponent(0.5)
    
            page.addAnnotation(highlight)
        })
    

    【讨论】:

    • 这应该在哪里调用?是否有选择文本时调用的委托方法?
    • 这将有助于作为参考:- pdftron.com/blog/ios/…
    猜你喜欢
    • 1970-01-01
    • 2020-12-13
    • 2016-05-01
    • 2017-07-26
    • 2012-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多