PTHighlights *hlts = [result GetHighlights];
[hlts Begin: doc];
while ( [hlts HasNext] )
{
NSLog(@"The current highlight is from page: %d", [hlts GetCurrentPageNumber]);
[hlts Next];
}
- (void)searchController:(OBDPDFSearchViewController *)searchController didSelectSearchResult:(PTSearchResult *)searchResult
{
[searchController dismissViewControllerAnimated:YES completion:nil];
[self clearSearchHighlights];
[self jumpToPage:searchResult.GetPageNumber];
PTHighlights *highlights = [searchResult GetHighlights];
[highlights Begin:self.pdfView.GetDoc];
[self.pdfView SelectWithHighlights:highlights];
PTSelection *selection = [self.pdfView GetSelection:self.pdfView.GetCurrentPage];
if (selection != nil)
{
[self.pdfView highlightSelection:selection withColor:[[UIColor obd_colorForType:OBDColorTypeRed] colorWithAlphaComponent:0.5]];
}
}
- (void)clearSearchHighlights
{
[self.pdfView ClearSelection];
[self.pdfView hideSelectedTextHighlights];
}
-----
If alternatively, you wanted to highlight ALL the results of a search, should be something like this.... (note that PDF view will only select items on the current page, so as you change pages, you have to update it)
- (void)searchFinished:(NSArray <PTSearchResult *> *)results
{
PTHighlights *allHighlights = [[PTHighlights alloc] init];
for (PTSearchResult *aResult in results)
{
[allHighlights Add:[aResult GetHighlights]];
}
[allHighlights Begin:self.pdfView.GetDoc];
[self.pdfView SelectWithHighlights:allHighlights];
[self updateHighlights];
}
- (void)pageNumberChangedFrom:(int)oldPageNumber To:(int)newPageNumber
{
[self updateHighlights];
}
- (void)updateHighlights
{
PTSelection *selection = [self.pdfView GetSelection:self.pdfView.GetCurrentPage];
if (selection != nil)
{
[self.pdfView highlightSelection:selection withColor:[[UIColor obd_colorForType:OBDColorTypeRed] colorWithAlphaComponent:0.5]];
}
}
----
Hope that is helpful