Quote:
Originally Posted by smasher
|
I have a pdf loaded onto a UIWebView. I want to do search of a string in that PDF. So I used these steps
Code:
NSString* addressText =[NSString stringWithFormat:searchBar.text];
NSString *javaSript=[NSString stringWithFormat:
@"var highlightStartTag = \"<font style='color:blue; background-color:yellow;'>\";"
" var highlightEndTag = \"</font>\";"
" var bodyText = document.body.innerHTML;"
" var searchTerm=%@;"
" var newText = \"\";"
" var i = -1;"
" var lcSearchTerm = searchTerm.toLowerCase();"
" var lcBodyText = bodyText.toLowerCase();"
" while (bodyText.length > 0){"
" i = lcBodyText.indexOf(lcSearchTerm, i+1);"
" if (i < 0){"
" newText += bodyText;"
" bodyText = "";}"
" else{"
" if (bodyText.lastIndexOf(\">\", i) >= bodyText.lastIndexOf(\"<\", i)){"
"if (lcBodyText.lastIndexOf(\"/script>\", i) >= lcBodyText.lastIndexOf(\"<script\", i)){"
" newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;"
" bodyText = bodyText.substr(i + searchTerm.length);"
" lcBodyText = bodyText.toLowerCase();"
" i = -1;"
" }"
" }"
" }"
" }"
" bodyText = newText;"
" document.body.innerHTML = bodyText;",addressText];
[webView stringByEvaluatingJavaScriptFromString:javaSript];
But it seems to have no effect. Dont this work on a pdf loaded onto a webView. I have been doing this thing for about 3 days. Plz give me some idea.