WWDC 2017 feature mini-demos: PDFKit
20 Jun 2017 · 3 min read
We continue testing the best iOS 11 features that were announced at WWDC! In this post, we dive into PDFKit.
Each year, our developers dive into the fresh material announced during Apple’s WWDC. In this series of mini-articles, we wanted to share our take on a few of the best new iOS 11 features!
A useful new addition to iOS 11 is PDFKit, a library to display and edit PDFs. Previously, this wasn’t included natively, leaving developers to work with third-party libraries for PDFs.
So what’s new? PDFKit offers the same native PDF rendering you find in Apple’s own apps (Preview, iBooks, Safari).
That’s is why we were excited to dive into the possibilities, using the app we built for Belgian newspaper De Tijd as a test case. Currently, De Tijd’s application uses a paid third-party PDF library, so we’re eager to dive in with Apple’s free, much more customisable offering.
First on the customisations checklist: you can alter the way pages are displayed. You can choose between horizontal and vertical scrolling, showing 1 or 2 pages, and having the first page displayed individually, like in a book.
For De Tijd, we set displayMode to show two pages horizontally.
When we tried using the displaysAsBook property, which shows the first page of the pdf centered (which is how the existing De Tijd app works), we encountered a bug. Enabling it causes the rest of the PDF’s pages to be misaligned, as you can see in the screenshot below.
You can also customise the thumbnail list for navigating the PDF. Third-party libraries usually provide their own UI – take it or leave it. While Apple provides you with a default thumbnail scrubber to switch between pages, you can also build your own custom thumbnail scrubber, which we set out to do.
You can render thumbnail images for each page in the PDF Document individually, giving you the opportunity to display them however you want. In this test, we put them in a horizontal collectionView, mimicking the exact implementation we currently have in the app.
Here, we ran into some more bumps in the road. For one thing, creating the thumbnails for the custom scrubber takes a while, creating some performance issues. The fact that rendering the thumbnails all happens on the main queue, caused some lag when scrolling. Our solution: fetching thumbnails in a background queue for smooth scrolling, and then caching them locally so they don’t need to be regenerated when cells are reused.
And finally, as you can see in the video, the rendering of new pages still seems a little slow and glitchy! But we’re convinced this is a problem that will be solved – it’s still a beta, after all.
A couple of extra noteworthy features that we didn’t use in this little demo? You can make your own forms with text fields, radio buttons, checkboxes etc. This opens up a lot of possibilities! And security has also been taken into account: PDFKit offers an extensive security feature set, including encryption, password locking, and disabling printing or copying.
Looking for a new gig where you can tweak iOS 11 to your heart’s content? Our friends at Spencer are looking for an extra pair of iOS hands…