【问题标题】:Text underline and highlight in PDF renderingPDF 渲染中的文本下划线和突出显示
【发布时间】:2023-03-24 23:53:02
【问题描述】:

我正在使用来自 git hub 的以下project 进行 PDF 渲染,但我需要为用户提供在 PDF 中添加下划线和突出显示文本的功能

但是当我尝试使用 Web 视图进行 PDF 渲染时,我能够突出显示文本而不是下划线

我也尝试使用 CGPDFDocument 进行 PDF 渲染,但我无法获得该功能来突出显示文本或下划线文本

我需要在PDF渲染中实现文本下划线和文本高亮也提取文本

任何帮助将不胜感激

谢谢

【问题讨论】:

    标签: iphone ios ipad pdf-generation


    【解决方案1】:

    我认为您可以轻松解决这个问题。试试这个:

    let selections = pdfView.currentSelection?.selectionsByLine()
    
        guard let page = selections?.first?.pages.first else { return }
    
        selections?.forEach({ selection in
    
            let highlight = PDFAnnotation(bounds: selection.bounds(for: page), forType: .underline, withProperties: nil)
            highlight.endLineStyle = .square
            highlight.color = UIColor.black.withAlphaComponent(1)
    
            page.addAnnotation(highlight)
            pdfView.document?.write(toFile: "PDF File Path")
        })
    

    你也可以将forType改成你想要的类型。 例如高亮、下划线、墨迹等。

    【讨论】:

    • 感谢安娜的回复!这个问题是在 2013 年我们不使用 swift 时提出的!无论如何,你的回答会对有需要的人有所帮助!
    【解决方案2】:

    使用iOS在PDF中进行注释并不容易,您可以使用Quartz Framework。你可以从这里得到一些参考

    add annotation to pdf

    add an annotation on a pdf

    annotate pdf within iphone sdk

    annotation notes comments using quartz 2d in ios

    或者你可以在这里查看一些库

    pspdfkit

    fastpdfkit

    html pdf viewer ios xcode project

    pdftouch sdk for ios

    poppler

    【讨论】:

      猜你喜欢
      • 2012-09-02
      • 1970-01-01
      • 2013-08-22
      • 1970-01-01
      • 1970-01-01
      • 2019-06-22
      • 1970-01-01
      • 2012-12-24
      • 2014-02-25
      相关资源
      最近更新 更多