I had the same issue - here’s my solution.
When a user selects a Search Result cell in my table view of results, this is the delegate callback in my PDF Controller:
- (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];
}
{
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
On Thursday, March 12, 2015 at 12:46:41 PM UTC-4, Mario Couture wrote:
On Wednesday, March 11, 2015 at 5:17:47 PM UTC-4, Ryan wrote:
The problem is that Highlights actually exposes the iterator pattern. Here is the code from TextSearcj objective-c sample.
PTHighlights *hlts = [result GetHighlights];
[hlts Begin: doc];
while ( [hlts HasNext] )
{
NSLog(@“The current highlight is from page: %d”, [hlts GetCurrentPageNumber]);
[hlts Next];
}
If you call [hlts GetCurrentQuads] you will get the quads.
Thanks for that, I can now see that I do get highlights data, but it still does not display in the viewer, isn’t the method SelectWithHighlights on the PTPDFViewCtrl class (_pdfView below) suppose to take care of that?
in the code below I get an execution exception when trying to call GetCurrentQuads on hlts, but I was able to get call GetCurrentPageNumber and get the proper value for it.
if ([selection.resultObject isKindOfClass:[PTSearchResult class]]) {
PTSearchResult* result = (PTSearchResult*) selection.resultObject;
DDLogDebug(@"Showing Search Results at page %d (%@).",result.GetPageNumber,result.GetHighlights.GetCurrentQuads);
[_pdfView SetCurrentPage:result.GetPageNumber];
PTHighlights *hlts = [result GetHighlights];
[hlts Begin: _pdfDoc];
if (![_pdfView SelectWithHighlights:hlts]) {
DDLogDebug(@"Could not create selection from Highlights object");
}
while ([hlts HasNext]) {
DDLogDebug(@"The current highlight is from page: %d", [hlts GetCurrentPageNumber]);
PTVectorQuadPoint* vQuads = [hlts GetCurrentQuads];
if (![vQuads isEmpty]) {
for (int i =0; i < 8; i++) {
PTQuadPoint* qp = [vQuads get:i];
DDLogDebug(@"Quad Point1: %f, %f",qp.getP1.getX,qp.getP1.getY);
DDLogDebug(@"Quad Point2: %f, %f",qp.getP2.getX,qp.getP2.getY);
DDLogDebug(@"Quad Point3: %f, %f",qp.getP3.getX,qp.getP3.getY);
DDLogDebug(@"Quad Point4: %f, %f",qp.getP4.getX,qp.getP4.getY);
}
}
[hlts Next];
}
}