0

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

4

1 回答 1

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++;
        }
    }
}

有关更多详细信息,请查看PSCAddHighlightAnnotationProgrammaticallyExample我们的目录示例项目

以后,请联系 pspdfkit.com/support/request,我们的支持团队将在那里为您提供帮助。

于 2018-08-13T17:05:51.780 回答