Microsoft Windows Phone 8.1 support ends (13 Jul 2017)

Microsoft has ended support for Windows Phone 8.1

Questions about Android development and PDF

Search for String and goto Page

More
IP: 192.168.0.70 12 years 2 months ago #4939 by phron
Hello,
I'm opening a PDF via Intent and put a String with a keyword I want to search for with it. After the PDF is opened I want it to search for the given keyword and show the page where it has been found.

Opening the PDF and reading the keyword from intent is no problem, but I find no way to implement a method which search for the given keyword in the PDF.

Can you tell me how to write such a search-method ?
More
IP: 192.168.0.70 12 years 2 months ago #4940 by radaee
record the key word in Activity.
when first PDFReader.onSizeChanged() called.
invoke:
Code:
if( first called ) { m_view.vFindStrt m_view.vFind }
at end of PDFReader.onSizeChanged().
More
IP: 192.168.0.70 12 years 2 months ago #4947 by phron
Thank you for your answer.

What parameter is necessary for the vFind() method? Found in documentation that it is an integer value, named "int dir". But what should this "dir" be? An integer value for the directory? And how can I get the number of the page where a match has been found?
More
IP: 192.168.0.70 12 years 2 months ago #4974 by phron
:( an answer would be helpful. Main problem is how to find out on which page the search result has been found
More
IP: 192.168.0.158 12 years 2 months ago #4976 by nermeen
Using the above solution you can find the next occurence, vFind() takes the direction (1 for next, -1 for previous)
to get the page you can use: m_finder.find_get_page()..


You can alternatively use the following code to search yourself the entire pdf, and save the page number of the pages containing the search word:
Code:
int pagesCount = m_doc.GetPageCount(); for(int i = 0 ; i < pagesCount ; i++) { Page currentPage = m_doc.GetPage(i); currentPage.ObjsStart(); Finder mFinder = currentPage.FindOpen(str, false, false); if( mFinder != null ) { int finds = mFinder.GetCount(); for(int j = 0 ; j < finds ; j++) { System.err.println("page " + (i+1)); int foundIndex = mFinder.GetFirstChar(j); int phraseStartIndex = foundIndex - 50 < 0 ? 0 : foundIndex - 50; int phraseEndIndex = foundIndex + 50 < currentPage.ObjsGetCharCount() ? foundIndex + 50 : currentPage.ObjsGetCharCount() - 1; System.err.println("phrase " + currentPage.ObjsGetString(phraseStartIndex, phraseEndIndex)); } mFinder.Close(); } currentPage.Close(); }
Time to create page: 0.419 seconds
Powered by Kunena Forum