How to search by string programatically - RadaeePDF.com
Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about iOS development and PDF
  • Page:
  • 1

TOPIC: How to search by string programatically

How to search by string programatically 2 years 3 months ago #12132

  • luigav
  • luigav's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 1
  • Thank you received: 0
Hi,
I would like to create my own toolbar and do a search by string programatically. How I do it?

Please Log in or Create an account to join the conversation.

How to search by string programatically 2 years 3 months ago #12139

  • emanuele
  • emanuele's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 563
  • Karma: 21
  • Thank you received: 65
Hi,

you can use PDFPage find method to get a PDFFinder instance, then manage the search result.
Here is a simple method that shows how to get string occurrences in whole pdf:
- (void)customSearch:(PDFDoc *)doc ofString:(NSString *)string
{
    BOOL caseSensitive = NO;
    BOOL wholeWord = NO;
    
    for (int i = 0; i < doc.pageCount; i++) {
        
        // get page
        PDFPage *page = [doc page:i];
        [page objsStart];
        
        // find in page
        PDFFinder *finder = [page find:string :caseSensitive :wholeWord];
        
        // manage each search term contained in this page
        for (int c = 0; c < finder.count; c++) {
            
            // start position
            int firstCharPos = [finder objsIndex:c];
            NSLog(@"page: %i", i);
            NSLog(@"pos: %i", firstCharPos);
            // do custom actions
        }
    }
}

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Powered by Kunena Forum