问题描述
我已经寻找谷歌,计算器,和苹果的开发者库PDF批注,但没有人真正满足我的需要。这是我的问题,我目前的知识了,请纠正我,如果我错了。
I have searched for PDF annotation on Google, stackoverflow, and Apple's developer library but none of them really satisfies my need. Here is my problem and my current knowledge of it, please correct me if I'm wrong.
我想允许用户先选择几行文本高亮,然后画在上面他们突出的矩形。
I would like to allow users to first select some lines of text to highlight, and then draw highlighting rectangles on top them.
【提问】:我们如何选择按CGContextDrawPDFPage呈现的PDF页面上的文本()
的特别是,如果我要重写的touchesBegan /移动/端委托方法,我应该在那里,以跟踪用户想要选择?文本框做的
我不希望使用FastPDFKit,因为它会显示一个标志,收费金额,或UIWebView的,因为它是在物联网方面,我们可以用它做非常有限,再加上我想学习如何做这自己: - )
I don't want to use FastPDFKit because it displays a logo and costs money, or UIWebView because it is very limited in terms of things that we can do with it, plus I would like to learn how to do this myself :-)
谢谢!
德里克
Thanks!Derek
- 更新 -
潜在的解决方案:我可能把我的PDF上面的透明视图,在解析PDF内容,建立每TJ或TJ每串元素的矩形。这些矩形将是可选择的文,用户可以高亮显示。一个需要注意的是,某些PDF果酱几个字为一个TJ,所以从在这种情况下选择单个词prevents用户。我会尝试这种做法,以后更新的结果。
Potential solution: I could probably put a transparent view on top of my PDF, and while parsing the PDF content, build a rectangle for every Tj or every string element in TJ. Those rectangles would be the selectable "text" that users can highlight. One caveat is that some PDFs jam several words into one Tj, so that prevents users from selecting individual words in that case. I will try this approach and update the result later.
推荐答案
您潜在的解决方案是要走的路。一个TJ串的边界矩形的大小是边界字符串中的每个字形的长方形,所以你可以选择在字符串中的任何的总和。在PDFKitten库可以帮助您与文本处理:
Your potential solution is the way to go. The size of the bounding rectangle of a Tj string is the sum of bounding rectangles of each glyph in the string so you can select anything in the string. THe PDFKitten library might help you with text processing: https://github.com/KurtCode/PDFKitten
这篇关于如何选择一个PDF文本行,然后突出显示它们? (IOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!