Until now, we have pointed how to run some learning examples with the general purpose of getting familiar with the PlugPDF SDK. Thank you for having followed our series of posts “Building Android PDF Apps for Absolute Beginners” up to this point, you are becoming a professional application developer!
At this stage we are ready to design and implement our first practical Android PDF app: A PDF Protector. We strongly encourage you to develop together with us this security tool, adapt it to your particular needs and eventually upload it to Google Play.
This Android app enables users to password protect their PDF files by considering two different passwords: A user password and a master or owner password (as you prefer to call it). The user password’s goal is to protect the PDF file whenever it’s opened, while the master password is intended to protect the management tasks listed below from being performed on the document:
- Modify content
- Copy content
- Modify annotations
- Fill fields
- Document assembly
It is a good idea for smartphone users to put in place some basic security measures, for example as a rule of thumb sensitive files should always be encrypted. Keep in mind that any of us may end up with too many apps installed on our Android, some of them being able to access our device’s features: SD card, location, calendar, etc.
PlugPDF Protector comes to the rescue in a number of scenarios:
- The user filled a PDF job application form adding some confidential information (for instance his/her national identity card) and wants to protect their document
- The user downloaded a bank statement from their email account and needs to restrict access to that file
- In general, a PDF is downloaded from a website and the end user wants to encrypt that file
Encrypting PDFs with PlugPDF Protector
Let’s take a first GUI approach in our project development. This is the user flow for encrypting a PDF document.
Figure 1. The user is asked to pick a PDF file from their SD card
Figure 2. This screen is displayed if the PDF is not protected with a password
Figure 3. Otherwise, the Password dialog is prompted
Figure 4. The user updates his/her password and then clicks the Accept Button
Notice how the main screen allows to type a User Password and an Owner Password. On the other hand, there’s also a set of tasks to be optionally selected.
Recall that the User Password is for protecting the PDF document when it is opened. And the Owner Password, which is also called master password, is for protecting common management operations: Print, modify content, copy content and so forth, as shown in the figure above.
Figure 5. The file is encrypted and the app displays this toast message: The file has been encrypted, thank you!
This time, as things get a bit more complicated we are using three Java classes instead of one only, as we did in previous examples. In alphabetical order:
Figure 6. PlugPDF Protector structure
SelectPDF are quite self-explanatory. However, the
EncryptPDF class has been documented for you to have a thorough look at its Java comments in order to understand how it works in detail.
This is where the domain logic is implemented. The core logic here is that one performed by the
encryptPDF method. Everything is executed by the
As you can see,
PasswordDialog is a password dialog already designed by PlugPDF which, remember, in addition to the core libraries comes with a set of generic PDF Java classes out of the box that make your life easier.
The PlugPDF SDK is initialized here in order to preserve the app’s global state during the Android execution flow.
This is the starting point from which the user flow is launched.
Here come the XML definitions required to understand the PDF protector’s big picture.
GPS navigators, digital cameras, contact databases, web browsers and so on. Today, smartphone devices are small interconnected computers running multiple applications of any kind. It is for this reason that users should take security measures and encrypt their sensitive data.
However, PlugPDF Protector comes to the rescue. This Android application allows to encrypt your PDFs with both a user password and an owner password. The former is for protecting files when unauthorized eyes want to open them and the latter aims to keep common management tasks safe.
Today’s Android tutorial has walked you through implementing a security tool with the PlugPDF SDK. Congratulations!, you are moving from being a beginner developer to being a professional one. Thank you for having followed this how-to up to this point.