【问题标题】:Select text from pdf in webview在 webview 中从 pdf 中选择文本
【发布时间】:2014-02-19 12:18:29
【问题描述】:

我正在使用图像中的UIGraphicsBeginPDFPageWithInfo 制作pdf,然后将该pdf 加载到UIWebView 中。

我想从该 pdf 中选择一些文本并将其显示在文本视图上。这是我用来在 Web 视图上加载 pdf 的代码示例。

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"images.pdf"];

NSURL *pdfUrl = [NSURL fileURLWithPath:filePath];
NSLog(@"pdf URL :: %@",pdfUrl);
NSURLRequest *request = [NSURLRequest requestWithURL:pdfUrl];
[_webView loadRequest:request];

我尝试过使用以下内容,但它返回的是一个空白字符串。

NSString *innerText = [_webView stringByEvaluatingJavaScriptFromString:@"document.body.innerText"];

edit:: 我想要 ibooks 中实现的文本选择功能。

【问题讨论】:

  • document.documentElement.innerText 是要走的路。但您无法使用 JavaScript 从 PDF 中读取文本。

标签: ios pdf uiwebview


【解决方案1】:

你能在 gitHub 中看到这个例子吗:https://github.com/KurtCode/PDFKitten

【讨论】:

  • 我已经看到了这一点,但没有关于如何从 pdf 中选择特定文本的信息。
猜你喜欢
  • 2019-05-16
  • 2010-11-09
  • 2011-08-28
  • 2013-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-10
相关资源
最近更新 更多