PDF下划线和高亮显示在文本中

问题描述 投票:2回答:2

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

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

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

我需要在PDF渲染中实现文本下划线和突出显示文本,也要提取文本

任何帮助将不胜感激

谢谢

iphone ios ipad pdf-generation
2个回答

0
投票
我认为您可以轻松解决该问题。尝试使用:

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

您也可以将Type更改为所需的类型。例如,突出显示,下划线,墨水等。
© www.soinside.com 2019 - 2024. All rights reserved.