PDFKit Highlight Annotation: quadrilateralPoints

北慕城南 提交于 2019-12-08 09:19:45

问题


I want to add highlight annotation into pdf file by using PDFKit. And I use this below code to add it.

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];

But it just highlight one rectangle, I want to highlight multiple lines text. I have found one question/answer Wrong highlight annotation on apple PDFKit

But it is not what I want, it will add many highlight annotations, I just want to add one annotation. And I learn that the key-value QuadPoints can do this. But it doesn't work when I add the below code, even can't render the annotation.

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;

So now I want to know how to implement it? or how to use quadrilateralPoints ?


回答1:


I have found the answer: below code works

NSArray<NSValue *> *quadrilateralPoints = [[NSArray alloc] initWithObjects:
                                       [NSValue valueWithCGPoint:CGPointMake(206.0 - 206, 659.0 - 600)],
                                       [NSValue valueWithCGPoint:CGPointMake(266.0 - 206, 659.0 - 600)],
                                       [NSValue valueWithCGPoint:CGPointMake(206.0 - 206, 600.0 - 600)],
                                       [NSValue valueWithCGPoint:CGPointMake(266.0 - 206, 600.0 - 600)],
                                       nil];

annotation.quadrilateralPoints = quadrilateralPoints;

because it is based on origin bounds



来源:https://stackoverflow.com/questions/49001157/pdfkit-highlight-annotation-quadrilateralpoints

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!