我想用PDFKit在PDF文件中添加高亮注解。我使用下面的代码来添加它。
PDFPage* page = [self.pdfView.document pageAtIndex:0];
PDFAnnotation* annotation = [[PDFAnnotation alloc] initWithBounds:CGRectMake(206, 600, 60, 59) forType:PDFAnnotationSubtypeHighlight withProperties:nil];
annotation.color = UIColor.blueColor;
[page addAnnotation:annotation];
但它只是突出显示一个矩形,我想突出显示多行文本。我找到了一个问题/答案Wrong highlight annotation on apple PDFKit
但它不是我想要的,它会添加许多突出显示注解,我只想添加一个注解。我了解到键值QuadPoints可以做到这一点。但是当我添加下面的代码时,它不起作用,甚至不能呈现注解。
NSArray<NSValue *> *quadrilateralPoints = [[NSArray alloc] initWithObjects:
[NSValue valueWithCGPoint:CGPointMake(206.0f, 659.0f)],
[NSValue valueWithCGPoint:CGPointMake(266.0f, 659.0f)],
[NSValue valueWithCGPoint:CGPointMake(206.0f, 600.0f)],
[NSValue valueWithCGPoint:CGPointMake(266.0f, 600.0f)],
nil];
annotation.quadrilateralPoints = quadrilateralPoints;
现在我想知道如何实现它。或如何使用quadrilateralPoints?
3条答案
按热度按时间eqzww0vc1#
我找到了答案:下面的代码工程
因为它基于原点边界
sigwle7e2#
我发现更好的方法是使用.quadPoints annotationKey。此方法符合PDF规范,并且不是PDFAnnotationUtilities. h文件的一部分,该文件是为了兼容遗留函数而提供的。这种方式不需要您调整边界。
要完成答案,您还应该使用PDFSelection的selectionsByLine函数来获取某个页面上的所有选择,并按照Wrong highlight annotation on apple PDFKit中的描述为每个页面添加一个注解
hmtdttj43#
我走上了同样的道路,但我遇到了更令人沮丧的事情。我似乎无法捕捉与触摸突出显示菜单元素的人相关的事件。见下图。我似乎无法捕捉到这一事件。我在10年前成功地完成了这一点,但不是用PDFView。