How to copy selected data from PDF displayed in UIWebView

I am working on a project that displays PDF in a UIWebView. I added another UIMenuItem to the UIMenuController to do various things with the text in the UIWebView that was selected. The problem is that I cannot access the selected text in my newly created selection method. If I first use the copy command in the selected text, then I can get this previously copied text from cardboard, but a command such as [myWebView copy: sender]; called from my new selector does nothing. How to get selected text in a new selector? I know this can be easily done using javascript when working with HTML in UIWebView, how do people usually do this with PDF files displayed in UIWebView?

0
source share
1 answer

You can call the copy command from the first responder using this code:

[[UIApplication sharedApplication] sendAction:@selector(copy:) to:nil from:self forEvent:nil];

Then you can simply remove it from the cardboard:

[UIPasteboard generalPasteboard].string;

This is apparently the only way to get selected text from a UIWebView that displays PDF, javascript methods will not work with PDF files, but only with HTML.

+4
source

All Articles