使用 ipad 的 drawLayer 渲染后在 PDF 上选择文本 [英] Text selection on PDF after rendering using the drawLayer for ipad

查看:24
本文介绍了使用 ipad 的 drawLayer 渲染后在 PDF 上选择文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 ipad 上渲染后突出显示 pdf 上的文本.我觉得我通过大量谷歌搜索和 fastPdfKit.通过此链接,我可以轻松解析 pdf 并尝试突出显示用户搜索中的文本.我正在使用以下方法获取文本边界:

I'm trying to highlight the text on the pdf after rendering on the ipad.I feel I'm achieving something with a lot of googling and the sample code provided by fastPdfKit. From this link I am parsing a pdf easily and trying to highlight text from a user search. I am using the below method to get text bounds:

-(NSArray *)searchResultOnPage:(NSUInteger)pageNr forSearchTerms:(NSString *)searchTerm withProfile:(MFProfile *)p;

这个方法给了我一个对象数组,我从中得到了矩形,但它不完全是搜索词的边界.

This method gives me an array of objects from which I am getting the rect but it is not exactly the searched word bounds.

谁能告诉我这是否是正确的方法,请告诉我如何正确获取文本边界.这个问题如何与我的上一个问题重复 (旧)

Can anyone tell me whether this is the correct way to go or not, and please tell me how to get the text bounds correctly. Some how this question is duplicate of my last question (old)

我接受建议.

谢谢.

推荐答案

(NSArray *)searchResultOnPage:(NSUInteger)pageNr forSearchTerms:(NSString *)searchTerm 返回 MFTextItems.MFTextItem 有一个名为 highlightPath 的属性,它返回一个 CGPathRef.那是你正在使用的吗?

(NSArray *)searchResultOnPage:(NSUInteger)pageNr forSearchTerms:(NSString *)searchTerm returns an NSArray of MFTextItems. MFTextItem has a property called highlightPath that returns a CGPathRef. Is that what you are using?

如果您需要从 highlightPath 获取 CGRect,您可以使用 CGPathGetBoundingBox.

If you need to get a CGRect from the highlightPath, you could use CGPathGetBoundingBox.

如果 highlightPath 对您来说不够准确,您将不得不发挥创造力并自行提出解决方案.

If the highlightPath is not accurate enough for you, you are going to have to be creative and come up with a solution on your own.

这篇关于使用 ipad 的 drawLayer 渲染后在 PDF 上选择文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆