3

I've been trying to highlight text in a pdf. After a lot of research and experiments, it seems like I have to find the bounding box of each glyphs, create an overlay where the actual drawing is happening, and highlight the text by filling the CGRect with the info from bounding box and fill it with color. Now, I am stumped with the bounding box.

I've been using the PDFKitten to search and highlight the text. Now I want to use it to select and highlight the text. What I don't understand is how does it use the bounding box ( as well as other information like ascent, descent, capHeight, etc.) to fill highlight the searched word. When I tried to access the FontDescriptor class to get the info, it displays this:

2012-06-28 16:32:20.626 er[2408:15203] x:-665, y:-325, width:2000, height:1006
2012-06-28 16:32:20.627 er[2408:15203] x:-157, y:-250, width:1126, height:952
2012-06-28 16:32:20.628 er[2408:15203] x:-628, y:-376, width:2000, height:1010

It is very confusing so if anyone can clarify this, it will be very much appreciated.

4

1 回答 1

1

您不能使用字体描述符信息来获取字形的边界框。

PDFKitten 负责使用 RenderingState 模型查找每个字形的宽度和高度。

您可以在扫描 PDF 时使用它来查找单词的位置。

字体字典提供字形的宽度。您可以使用 cid 获得字形的正确宽度。

尝试查看 PDFKitten 的突出显示代码。

于 2015-07-22T09:57:43.843 回答