Making an iOS application with the PlugPDF SDK

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.

Requirements

  1. An up-to-date version of both Xcode and iOS SDK, which can be downloaded from Apple’s developer site.
  2. The PlugPDF SDK supports XCode 5.0.2 onwards and iOS 5.1 onwards.

Steps required for making your first PDF iOS app

  1. Download the PlugPDF SDK
  2. Create a new Xcode project
  3. Add the PlugPDF framework
  4. Add some libraries
  5. Initialize the PlugPDF SDK
  6. 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!

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 trial license key is on its way!

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 3. PlugPDF_iOS folder structure

Figure 4. PlugPDF_iOS folder content

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:

79F53DB9HHF9GH88EDB5297FH28FC6488AECC4EF496FB95A96CHFBF5

Please keep your license in a secure place since it will be required to initialize your PlugPDF applications, as we will show later in this paper.

2. Creating a new Xcode project

Let’s follow the steps illustrated in the figures below and create our first PDF application.

Figure 5. Open Xcode and choose File > New > Project…

Figure 5. Open Xcode and choose File > New > Project…

Figure 6. Now select iOS > Application > Single View Application

Figure 6. Now select iOS > Application > Single View Application

Figure 7. Choose the options for your new project

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. Create Git repository

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

Figure 9. Select your sample project from the Xcode window as shown here

Figure 10. Choose File > Add Files to

Figure 10. Choose File > Add Files to “sample”…

Figure 11. Select both PlugPDF files

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

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

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

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

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.

Then we just have to call the PlugPDFUninit(); function from the applicationWillTerminate method.

By the way, don’t forget to import the PlugPDF.h file.

In a nutshell, make sure that your AppDelegate.m file is as follows:

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 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 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

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:

  • Rotate
  • Page display mode
  • Brightness
  • Outline
  • Search
  • Edit

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!

Then update your ViewController.m as follows:

To conclude, there’s one last important thing to notice:

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

Figure 19. Copy Bundle Resources

That’s it for now. We have already completed this tutorial for building an iOS PDF reader.