I am working on a project that displays a PDF in a UIWebView. I have added another UIMenuItem to the UIMenuController in order to do various things with the text in the UIWebView that has been selected. The problem is that I am not able to access the selected text in my newly created selector method. If I use the copy command on selected text first, then I can get that previously copied text from the pasteboard, but a command like [myWebView copy:sender]; called from my new selector does nothing. How can I receive the selected text in my new selector? I know this can be done easily with javascript when working with HTML in a UIWebView, how do people usually do this with PDF files displayed in a UIWebView?
Asked
Active
Viewed 486 times
1 Answers
4
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 retrieve it from the pasteboard:
[UIPasteboard generalPasteboard].string;
This seems to be the only way to receive the selected text from a UIWebView that is displaying a PDF, the javascript methods will not work with PDF files, only HTML.

bbrownd
- 525
- 1
- 6
- 14
-
I implement this solution on a proyect and I was wondering if is legal? – Alejandro Cotilla Feb 20 '13 at 18:08
-
I don't understand why this wouldn't be legal from a programming perspective, but I would be nice if someone more knowledgable might chime in. – bbrownd Feb 22 '13 at 00:15