An Overview of the PlugPDF Sample Project

At this stage you’ll probably have asked for your PlugPDF key and may well have followed this tutorial.

But, oops! Now that you have downloaded the PlugPDF SDK and, with your hardworking effort, have achieved to build the Android code, it has come to a point where you need some help in understanding how the PlugPDF sample code is organized. Don’t panic, you are still a friendly newbie.

An Overview of the PlugPDF Sample Project

Run the App and Look at the GUI

Well, first of all let’s run the sample application and see how it behaves from the point of view of a regular user who doesn’t have any Android knowledge, but just wants to run a PDF app from his/her mobile device. This is the easiest way to get started!

If you followed the steps explained in the post entitled Building the Sample Project with Android Studio, your Android project should be displaying to you these two modules: mainActivity and plugpdf.

mainActivity contains the sample project’s source code, whereas plugpdf is the PDF SDK itself.

Figure 1. mainActivity and plugpdf

Figure 1. mainActivity and plugpdf

Figure 2. Selecting the BlueStacks App Player as the running device

Figure 2. Selecting the BlueStacks App Player as the running device

Figure 3. This screen is displayed when running mainActivity

Figure 3. This screen is displayed when running mainActivity

As you can see in the figure above, the PlugPDF Sample Project’s main activity, whose main goal is to quickly show what the PlugPDF SDK allows you to do, displays a menu containing the options listed below.

  • Document View
  • Document View Without Controller
  • Encrypt PDF
  • Merge PDF
  • Annotation Export/Import
  • Extract Text

A Couple of Words About BlueStacks

Those of you who are familiar with BlueStacks will probably note that the main activity is run in this example by selecting the BlueStacks App Player as the running device.

In case you didn’t know, Android apps can be run on desktops in a number of different ways: via the Android emulator, Android on Intel Platforms, Android-x86 Project and ARC Welder for Chrome OS. That being said, the BlueStacks App Player enables Android applications to run on Windows and Mac with minimum effort, so it can be used as an alternative to the Android emulator.

BlueStacks is not a must, however is a development tool to be considered on your daily tasks, which may come to the rescue for when your Android emulator can’t be started because whatever reason: Hardware acceleration issues, etc.

The Anatomy of the Sample Project

As any other Android project, the PlugPDF Sample Project consists of XML manifests, Java files, resources and assets.

The Anatomy of the Sample Project

Figure 4. The anatomy of the Sample Project

The App’s Main Menu

The sample\mainActivity\src\main\res\layout\main.xml linear layout is responsible for statically creating the main menu via XML annotations.

Then, the onCreate method of the MainActivity class will display the menu on the screen.

Main Activity Overview

Don’t get overwhelmed by the nuts and bolts of the Java code when delving into the MainActivity file (by the way, don’t forget to rename the file extension to .java once the file is downloaded on your computer).

This code handles some important Android concepts such as intents, activities and listeners. However, for now it is ok to know that MainActivity is the starting point which displays the app’s main menu and responds to the user’s interaction with the GUI (Graphic User Interface).

Android PDF SDK Apps

The PDF Viewers

As noted before, the sample folder walks you through what you can do with the PlugPDF SDK: View PDF documents, encrypt PDFs, merge PDFs, import/export annotations from/to XFDF files and extract text from documents. That, in a nutshell, is the idea behind the PlugPDF Sample Project.

Now that you have a good grasp at the big picture we will end up looking at the first two menu options: Document View and Document View Without Controller.

Figure 5. The user clicks on the Document View option

Figure 5. The user clicks on the Document View option

Figure 6. The user clicks on the Document View Without Controller option

Figure 6. The user clicks on the Document View Without Controller option

Figure 5 corresponds to the documentView\ReaderWithControllerActivity.java file.

And Figure 6 is launched by the documentViewWithoutController\ReaderActivity.java file.

The main difference between both PDF viewers is that ReaderWithControllerActivity creates a SimpleDocumentReader object whereas ReaderActivity instantiates an object of type ReaderView, which is the same as saying that the former is a complete PDF viewer that provides controllers (it comes with a top toolbar and a bottom slide bar) and the latter is a basic one with no controllers (it just does the job of displaying a PDF document).

Extending the Android Application Class

It’s beyond the scope of this post to go into a detailed explanation about every aspect of Android development or the PlugPDF SDK, nevertheless, we have considered important to mention that it is necessary to initialize PlugPDF in order to bring your Android PDF app to life.

So last but not least, please get a glimpse of the PlugPDFLauncherApplication.java file.

In this particular case you’ll notice that PlugPDFLauncherApplication is extending the Android Application class to initialize the SDK from within the onCreate() method. This way the valid license can maintain the global application state required for the app to fully operate.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *