ComPDFKit PDF SDK offers developers an API for programmatic full-text search, as well as UI for searching and highlighting relevant matches.
- Asynchronously finds all instances of the specified string in the document, use function
/**
* Called when the beginFindString:withOptions: or findString:withOptions: method begins finding.
*/
- (void)documentDidBeginDocumentFind:(CPDFDocument *)document;
/**
* Called when the beginFindString:withOptions: or findString:withOptions: method returns.
*/
- (void)documentDidEndDocumentFind:(CPDFDocument *)document;
/**
* Called when a find operation begins working on a new page of a document.
*/
- (void)documentDidBeginPageFind:(CPDFDocument *)document pageAtIndex:(NSUInteger)index;
/**
* Called when a find operation finishes working on a page in a document.
*/
- (void)documentDidEndPageFind:(CPDFDocument *)document pageAtIndex:(NSUInteger)index;
/**
* Called when a string match is found in a document.
*
* @discussion To determine the string selection found, use the selection.
*/
- (void)documentDidFindMatch:(CPDFSelection *)selection;
CPDFDocument::findString:withOptions:
.Each hit gets added to an NSArray
object as a object. If there are no hits, this method returns an empty array. Use this method when the complete search process will be brief and when you don’t need the flexibility or control offered by CPDFDocument::beginFindString:withOptions:
.
- Cancels a search initiated with CPDFDocument::beginFindString:withOptions:
,use function CPDFDocument::cancelFindString
.
- Highlighting Search Results, offers a way to both add and clear search results, use function.
PDF text contents are stored in objects which are related to a specific page. class can be used to retrieve information about text in a PDF page, such as single character, single word, text content within specified character range or bounds and more.
- (CPDFSelection *)selectionForPage:(CPDFPage *)page fromPoint:(CGPoint)fPoint toPoint:(CGPoint)tPoint {
NSInteger fCharacterIndex = [page characterIndexAtPoint:fPoint];
NSInteger tCharacterIndex = [page characterIndexAtPoint:tPoint];
NSRange range = NSMakeRange(fCharacterIndex, tCharacterIndex - fCharacterIndex + 1);
CPDFSelection *selection = [page selectionForRange:range];
return selection;
}