PDF Content

So, if you’ve been putting any PDF content in your iPhone apps, you — like us — probably fall into the category described here:

PDF parsing is a black art that most programmers avoid. “Madness lurks here.” They mumble to themselves quietly. Choosing instead to push their PDFs through UIWebViews and commit other crimes against humanity…

Well, we’d call it “path of least resistance” rather than “crimes against humanity” per se … but essentially yes.

… It doesn’t have to be this way, however. Parsing, displaying, and searching PDFs natively and at a low level is actually surprisingly easy if you’re not afraid to get your hands a little dirty with the Core Graphics PDF functions. I’m going to show you how.

And, indeed, it actually is not all that hard to display PDFs using Core Graphics. Still harder than UIWebView, mind you, so why bother? Why, because if you’re controlling the display and pagination, you can integrate the search engine strategy the post goes on to describe:

One of the things that seems to be particularly scary to programmers is searching PDFs. I agree that it’s certainly not pleasant stuff to code, but it’s not hard either.

Now, I want to preface this by saying that I feel this code is a bit of a hack, but it definitely works, and seems to work quite well…

Perhaps not the most confidence-inspiring of attestations, but hey it’s code you don’t have to write, and that’s always the best kind, isn’t it now?

h/t: iPhoneSDK!


Another take on the process here:

Rendering PDF is easier than you thought

Alex | January 21, 2010

Leave a Reply