- Posts: 3
- Thank you received: 0
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
IP: 192.168.0.70
12 years 2 months ago #4939
by phron
Search for String and goto Page was created 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 ?
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 ?
IP: 192.168.0.70
12 years 2 months ago #4940
by radaee
Replied by radaee on topic Search for String and goto Page
record the key word in Activity.
when first PDFReader.onSizeChanged() called.
invokeļ¼
at end of PDFReader.onSizeChanged().
when first PDFReader.onSizeChanged() called.
invokeļ¼
Code:
if( first called )
{
m_view.vFindStrt
m_view.vFind
}
IP: 192.168.0.70
12 years 2 months ago #4947
by phron
Replied by phron on topic Search for String and goto Page
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?
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?
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
Replied by phron on topic Search for String and goto Page
IP: 192.168.0.158
12 years 2 months ago #4976
by nermeen
Replied by nermeen on topic Search for String and goto Page
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:
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