如何在目标C

时间:2018-08-13 14:15:11

标签: ios objective-c pspdfkit

我正在使用PSPDFKit进行pdf编辑,我无法突出显示PDF中的文本,请帮助了解如何在Objective C中使用PSPDFkit突出显示文本。

1 个答案:

答案 0 :(得分:1)

您可以在iOS的PSPDFKit中以编程方式突出显示文本,如下所示:

PSPDFDocument *document = [PSCAssetLoader documentWithName:PSCAssetNameAnnualReport];
document.annotationSaveMode = PSPDFAnnotationSaveModeDisabled; // don't confuse other examples.

// Let's create a highlight for all occurrences of "bow" on the first 10 pages, in Orange.
NSUInteger annotationCounter = 0;
for (NSUInteger pageIndex = 0; pageIndex < 10; pageIndex++) {
    PSPDFTextParser *textParser = [document textParserForPageAtIndex:pageIndex];
    for (PSPDFWord *word in textParser.words) {
        if ([word.stringValue isEqualToString:@"bow"]) {
            PSPDFHighlightAnnotation *annotation = [PSPDFHighlightAnnotation textOverlayAnnotationWithGlyphs:[textParser glyphsInRange:word.range] pageRotation:[document pageInfoForPageAtIndex:pageIndex].rotation];
            annotation.color = UIColor.orangeColor;
            annotation.contents = [NSString stringWithFormat:@"This is an automatically created highlight #%tu", annotationCounter];
            annotation.pageIndex = pageIndex;
            [document addAnnotations:@[annotation] options:nil];
            annotationCounter++;
        }
    }
}

有关更多详细信息,请查看我们的catalog sample project中的PSCAddHighlightAnnotationProgrammaticallyExample

将来,请访问pspdfkit.com/support/request。我们的支持团队将为您提供帮助。