RadaeePDF.com :: Topic: Search for String and goto Page (1/1)
Welcome, Guest
Username: Password: Remember me

Signin/Signup with:

Questions about Android development and PDF

TOPIC: Search for String and goto Page

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

  • phron
  • phron's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Karma: 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 3 years 6 months ago #4940

  • radaee
  • radaee's Avatar
  • OFFLINE
  • Moderator
  • Posts: 825
  • Thank you received: 10
  • Karma: 43
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 3 years 6 months ago #4947

  • phron
  • phron's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Karma: 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 3 years 6 months ago #4974

  • phron
  • phron's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Karma: 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 3 years 6 months ago #4976

  • nermeen
  • nermeen's Avatar
  • OFFLINE
  • Moderator
  • Posts: 660
  • Thank you received: 38
  • Karma: 17
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.
Powered by Kunena Forum