Hi,
What is the best way to get a string for a block of highlighted text in PDF
Kit, given a PDFAnnotationMarkup object? I've tried several approaches, but
none of them deals with overlaps in the quadrilateralPoints, gets the text
bounds correct, and adds spaces between lines of text. For example, the
following will sometimes get words before and after the highlighted text for
some reason:
NSArray *quadPoints = [annotation quadrilateralPoints];
NSRect bounds = [annotation bounds];
PDFSelection *selection = nil;
for(j=0; j < [quadPoints count]; j+=2) {
NSPoint start = [[quadPoints objectAtIndex:j] pointValue], end =
[[quadPoints objectAtIndex:j+1] pointValue];
// quadrilateralPoints are relative to the annotation's bounds
start.x += bounds.origin.x;
start.y += bounds.origin.y;
end.x += bounds.origin.x;
end.y += bounds.origin.y;
if(!selection)
selection = [pdfPage selectionFromPoint:start toPoint:end];
else
[selection addSelection:[pdfPage selectionFromPoint:start
toPoint:end]];
}
// add spaces between lines of text
NSMutableString *string = [NSMutableString string];
for(PDFSelection *mSelection in [selection selectionsByLine]) {
[string appendString:[mSelection string]];
[string appendString:@" "];
}
Thanks,
Ryan_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]