0

I am using PSPDFKit for pdf edit,I am unable to highlight text in PDF please help to know how to highlight text using PSPDFkit in Objective C.

Lucky
  • 325
  • 1
  • 3
  • 16

1 Answers1

1

You can highlight text programmatically in PSPDFKit for iOS, like so:

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

For more details, take a look at PSCAddHighlightAnnotationProgrammaticallyExample from our catalog sample project.

In the future, please reach out to pspdfkit.com/support/request and our support team will help you in there.

Rad Azzouz
  • 59
  • 5