Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about Android development and PDF
  • Page:
  • 1

TOPIC:

Search for String and goto Page 10 years 3 months ago #4939

  • phron
  • phron's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 3
  • Thank you received: 0
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 ?
The topic has been locked.

Search for String and goto Page 10 years 3 months ago #4940

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
record the key word in Activity.
when first PDFReader.onSizeChanged() called.
invoke:
if( first called )
{
  m_view.vFindStrt
  m_view.vFind
}
at end of PDFReader.onSizeChanged().
The topic has been locked.

Search for String and goto Page 10 years 3 months ago #4947

  • phron
  • phron's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 3
  • Thank you received: 0
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?
The topic has been locked.

Search for String and goto Page 10 years 3 months ago #4974

  • phron
  • phron's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 3
  • Thank you received: 0
:( an answer would be helpful. Main problem is how to find out on which page the search result has been found
The topic has been locked.

Search for String and goto Page 10 years 3 months ago #4976

  • nermeen
  • nermeen's Avatar
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 962
  • Thank you received: 87
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:
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();
}
The topic has been locked.
  • Page:
  • 1
Powered by Kunena Forum