perra perra - 1 year ago 108
iOS Question

iOS PDF native search

I need to present and open pdf documents in my app. I would like to avoid third part libraries, because of update reasons (and I couldn´t find anyone created in swift).

I have been looking at QLPreviewController, UIDocumentInteractionController and presenting the pdf in an UIWebView. All these alternatives works fine for just presenting the pdf but I can´t find any built in search. I want functionality like the iBooks app.

Any advice is appreciated!

Answer Source

You'll likely wont find any 3rd-party frameworks written in Swift yet, simply because as of Swift 2.2 it's not binary compatible yet, and any binary framework written in Swift would be very fragile to break with even a minor update of Xcode (and updates to the compiler, that is).

I'm working on the commercial available PSPDFKit SDK for both iOS and Android. We're actually using a lot of C++ internally since raw performance is very important and Objective-C (and for many things, also Swift) are not yet fast enough for certain tasks.

We did invest a lot of time in adopting the latest Objective-C features such as nullability and generics next to declarations such as noescape for block-based API to make our SDK great to consume from within Swift.

While a separate Swift-wrapper could offer additional convenience, you'll find it very simple to use, and we're always working to adopt more features that improve bridging as they come available - there are a few interesting things in the Swift 3 proposals.

If you do not want to go the framework route, you can use CGPDFScanner to base a custom text extraction engine on. You will need to read up on Character Map Parsing - Page 446ff and many other sections - extracting text from a PDF document is surprisingly difficult, and after much work you'll be left with individual glyph positions and need to approximate where words are and if the document uses spaces or if you need to synthesize your own to correctly extract text. It's something that just takes a lot of experimentation and approximation to get right.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download