Search code examples
iospdfuiwebviewuipageviewcontroller

Possible to show PDF over a PageViewController in an iOS app?


I am developing a mobile app in which I need to highlight PDF text after searching and I am using PDF kitten library for this.

Library link: https://github.com/KurtCode/PDFKitten

From this I got number of selections on the PDF as well as the content of the PDF but I am unable to highlight text as the PDF is loaded on the webview. Is this possible, to add my PDF document over pageview controller and highlight text over it.


Solution

  • First, create a new instance of the scanner.

    CGPDFPageRef page = CGPDFDocumentGetPage(document, 1);
    Scanner *scanner = [Scanner scannerWithPage:page];
    

    Set a keyword (case-insensitive) and scan a page.

    NSArray *selections = [scanner select:@"happiness"];
    

    Finally, scan the page and draw the selections.

    for (Selection *selection in selections)
    {
        // draw selection
    }
    

    and then highlight the selections using core graphics framework.