如何使用目标C使用PSPDFKIT(iOS)突出显示文本

问题描述 投票:0回答:1

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

ios objective-c pspdfkit
1个回答
1
投票

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

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中的catalog sample project

将来,请联系pspdfkit.com/support/request,我们的支持团队将帮助您。

© www.soinside.com 2019 - 2024. All rights reserved.