This tutorial walks you through the necessary steps to run a simple, fully functional mobile PDF reader on an iOS device. The goal is to get familiar with some basic PlugPDF concepts, as well as to build your first Objective-C application with Xcode.
An up-to-date version of both Xcode and iOS SDK, which can be downloaded from Apple’s developer site.
The PlugPDF SDK supports XCode 5.0.2 onwards and iOS 5.1 onwards.
Steps required for making your first PDF iOS app
Download the PlugPDF SDK
Create a new Xcode project
Add the PlugPDF framework
Add some libraries
Initialize the PlugPDF SDK
Build the PDF viewer
1. Download the PlugPDF SDK
Download either a free trial license or an indie license as shown in the figure below.
Figure 1. Download PlugPDF now!
You will then be redirected to a web page from which both PlugPDF for Android and iOS can be downloaded:
Figure 2. Thank you, your license key is on its way!
This is what the PlugPDF_iOS folder looks like.
Figure 3. PlugPDF_iOS folder structure
Figure 4. PlugPDF_iOS folder content
On the other hand, you’ll instantly receive an email with your PlugPDF license key consisting of 56 alphanumeric characters like this example:
Figure 6. Now select iOS > Application > Single View Application
Figure 7. Choose the options for your new project
Now Xcode will ask you to place your project under control version. By the way, this issue is not actually important for building your first PDF application, nevertheless let’s activate this default feature just to finish with the wizard.
Figure 8. Select the Create Git repository checkbox, and finally click on the Create button
3. Adding the PlugPDF framework
At this point, we are adding both the PlugPDF.framework and the PlugPDF.bundle to the sample project. The former is the PDF library itself, while the latter contains the resources such as the fonts and images to be used.
Figure 9. Select your sample project from the Xcode window as shown here
Figure 11. Select both PlugPDF files as illustrated in this image and click on the Add button
If everything is ok your Xcode project navigator will display the PlugPDF.framework and the PlugPDF.bundle.
Figure 12. Xcode project navigator
4. Adding libraries
We must now add the libstdc++.dylib,libc.tbd,and libz.dylib libraries as well as the AVFoundation framework. So, first choose Build Phase > Link Binary With Libraries and then press on the + button as shown in the figure below.
Figure 13. Click on the + button
Use the search box when the dialog window is opened, and easily find these two dynamic libraries.
Figure 14. Adding the libstdc++.dylib and libz.dylib libraries
The last step is adding the AVFoundation.framework, after which the Linked Frameworks and Libraries will be properly set. Finally make sure that your project is set like this figure.
Figure 15. Linked Frameworks and Libraries
5. Initialize the PlugPDF SDK
The PlugPDF SDK is initialized from within the AppDelegate.m file by calling the PlugPDFInit function from the didFinishLaunchingWithOptions method.
At this stage we can already run our first PDF application; if everything is ok Xcode will launch the iOS simulator.
6. Building the PDF viewer
In the previous section we have first created a Single View Application and then we’ve successfully initialized the PlugPDF SDK in the AppDelegate.m file, however we still haven’t seen any of the cool PDF features and classes that are at our disposal. With the PlugPDFDocumentViewController class, embedding the following fully functional PDF reader into your iOS app is really a snap.
Let’s look at this example:
Figure 16. The user is displayed the Gone With the Wind button
Figure 17. The PDF ebook is opened once the button above is clicked
Figure 18. The main tool bar is displayed when clicking on the top of the simulator’s screen
This simple yet effective PDF reader comes with these tools:
Page display mode
How can you embed this PDF reader into your app? Well, just open your AppDelegate.m file and create an UINavigationController object in the didFinishLaunchingWithOptions. This takes a couple of lines of code!
Indeed, our sample code is loading a PDF file called Gone_With_the_Wind.pdf but you can refer to any PDF file; in either case please add your PDF file to Xcode’s Copy Bundle Resources, otherwise you’ll get this error: Exception CorruptedPDF Thrown when a pass-in data or file is not PDF document or corrupted.
Figure 19. Copy Bundle Resources
That’s it for now. We have already completed this tutorial for building an iOS PDF reader.