My First Functional Mobile PDF Reader

In the previous post, you have created a simple PDF picker in the blink of an eye by using the ReaderView class. That trivial exercise was basically intended to introduce you the PlugPDF SDK, but that’s the tip of the iceberg!

In addition to the core PlugPDF libraries which provide you with many cool features for managing PDF files, our PDF SDK comes out of the box with a set of Java classes to make your life very easy.

My First Functional Mobile PDF Reader

In fact, you don’t need to learn in detail how the PlugPDF API works. These Java files come with a friendly graphic user interface (GUI) already implemented. If your project’s deadline is looming and therefore you are in a hurry they will help you embed easy and fast a fully functional PDF reader in your Android app.

Our custom GUI can be freely used and modified by those developers purchasing a PlugPDF license. However, of course you are not forced to use the default GUI; the visual part of your apps can be designed and implemented as you wish by dealing yourself with the core PlugPDF classes such as PDFDocument or ReaderView.

The Default GUI

Let’s have a look at the Java files implementing the look and feel of the PDF viewer.

This is how the default GUI is structured

Figure 1. This is how the default GUI is structured

As you may have noticed, the SimpleDocumentReader class is the most important Java file of all the above, so to speak. It is actually the PDF reader working in conjunction with the Java classes starting with the word “Simple”.

This is how the default simple document reader looks

Figure 2. And this is how the default simple document reader looks

This simple yet effective PDF reader, whose XML definition can be found in the res/layout/simple_reader_control.xml file, comes with the tools listed below.

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

Rotate

Figure 3. Rotate

Page display mode

Figure 4. Page display mode

Brightness

Figure 5. Brightness

Outline

Figure 6. Outline

Search

Figure 7. Search

Edit

Figure 8. Edit

Purchase a PlugPDF license today!, and feel free to browse the code and perform any changes you want to make; otherwise you can download either a free trial version or an indie license. Indeed, this other post shows how to customize the navigation bar by updating some controls in the SimpleReaderControlView class.

Those of you who have a basic understanding of Android will find this is very easy to do, however this time we are not customizing the predetermined navigation bar but putting the SimpleDocumentReader into action, which is a snap!

Embedding Your First PDF Reader into Your Android App

Embedding Your First PDF Reader into Your Android App

Once again we are assuming that you’ve already created a new Android project called SimpleDocumentReader and have imported the plugpdf module. We’ll also suppose that there is a third-party file manager installed on your Android device. For more information on these prerequisites please read this post.

You should end up with a project anatomy like this:

You should end up with a project anatomy like this

Figure 9. A new Android project and the plugpdf module are already created and imported, respectively

Customize the Main Activity

MainActivity.java file for the user to choose PDF files from their SD card and display a functional PDF reader.

Updating the XML Files

manifests/AndroidManifest.xml file:

res/layout/activity_main.xml file:

Running the Simple Document Reader

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

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

The PDF document selected by the user is displayed

Figure 11. The PDF document selected by the user is then displayed

The user taps once on the screen

Figure 12. When the user taps once on the screen the navigation bar is shown

What’s the Code Doing?

The main activity’s Java code is pretty similar to that one introduced in the previous post. The basic difference is that now we are instantiating a SimpleDocumentReader object:

While in the Simple PDF Picker example we created a ReaderView object:

SimpleDocumentReader is a functional custom GUI which enables you to quickly build native PDF readers.

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 *