Making an Android application with the PlugPDF SDK

This tutorial walks you through the necessary steps to run a simple, fully functional mobile PDF reader on an Android device. The goal is to get familiar with some basic PlugPDF concepts, as well as to build your first PDF Android application with Android Studio.

Requirements

  1. An up-to-date version of Android Studio and SDK tools, which can be downloaded from Android’s Developer site.
  2. The PlugPDF SDK supports Android SDK 3.2 (Honeycomb, API 13) onwards.

Steps required for making your first PDF Android app

  1. Download the PlugPDF SDK
  2. Create a new Android project
  3. Add the PlugPDF framework
  4. Compile the plugpdf module
  5. Initialize the PlugPDF SDK and build the sample 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_Android folder looks like.
Figure 3. The PlugPDF_Android folder’s structure and content

Figure 3. The PlugPDF_Android folder’s structure and 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. Create a new Android project

Figure 4. Create a new Android project

Figure 4. Open Android Studio and choose File > New > New Project…

Figure 5. Configure your new project

Figure 5. The Create New Project wizard will start. The first step is to fill the New Project dialog as shown here

Figure 6. Target Android Devices

Figure 6. Select API 15 (IceCreamSandwich) as the minimum SDK in the Target Android Devices dialog

Figure 7. Add an activity to Mobile

Figure 7. Add a blank activity to your project

Figure 8. Customize the Activity

Figure 8. Finally, customize your activity as it is shown here, and click Finish

3. Add the PlugPDF framework

The next step is importing the PlugPDF SDK.
Figure 9. Choose File > New > Import Module...

Figure 9. Choose File > New > Import Module…

Figure 10. Select the plugpdf folder

Figure 10. Select the plugpdf folder from the PlugPDF_Android directory and click Finish

Now wait a few seconds until the Gradle execution finishes, at the end of this process your Android Studio should look like the image below.
Figure 11. app and plugpdf modules

Figure 11. app and plugpdf modules

By the way, at this point you may get this error: Failed to sync Gradle project ‘Sample’. Cause: failed to to find target with hash string ‘android-15’. In that case, please open the Android SDK Manager and make sure to install the SDK Platform Android 4.0.3, API level 15.

4. Compile the plugpdf module

The plugpdf module needs to be compiled so that the PlugPDF SDK’s Java object types will be recognized; otherwise, Android Studio will show the notice “Cannot resolve symbol” when trying to identify PlugPDF types such as the following:

  • PlugPDF
  • PlugPDFException
  • SimpleDocumentReader
  • SimpleDocumentReaderListener
  • DocumentState

This is because the compile project(':plugpdf') dependency must be added to the (Module: app) gradle script as shown below:

5. Initialize the PlugPDF SDK and build the sample PDF viewer

Let us recapitulate. At this stage we’ve just created a new Android application with a blank activity. Well, now make sure to update the following three files in order to run the sample PDF reader:

  • AndroidManifrest.xml
  • content_main.xml
  • MainActivity.java

As it illustrated below:

AndroidManifrest.xml file:

content_main.xml file:

MainActivity.java file:

Running the Simple Document Reader

Congratulations! Finally we are ready to run the application. As you will notice this simple yet effective PDF reader comes out of the box with these powerful features.

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

The user is asked to pick a file from their SD card

Figure 12. The user is asked to pick a file from their SD card

The PDF document selected by the user is displayed

Figure 13. The PDF document selected is then displayed

Rotate

Figure 14. The user taps on the screen and the navigation bar is shown