• Android Solutions

    Android Solutions

    qPDF Notes, qPDF Viewer, and the qPDF Toolkit are first-in-class in reliability, performance, and usability and deliver the most advanced Android PDF technology available.

qPDF Toolkit Developer Guide Documentation

qPDF Toolkit – Developer Guide

Contents

Introduction
Getting Started
Create a new document
Modify an existing document
QPDFViewerView – A PDF viewer component
QPDFNotesView – A PDF viewer and annotation component
Obfuscate with ProGuard

Javadoc API
Source Code Samples

Introduction

qPDF Toolkit is an Android toolkit that integrates into your Android app so that you can provide PDF functionality to your end users. The toolkit provides a wide range of functions to create, modify and render PDF documents.

The toolkit can be used to integrate a full featured PDF viewer right into your own app that can be customized to meet the needs of your app. fun

  • Render PDF content, to implement an integrated PDF viewer.
  • Convert PDF content to Bitmap objects to export images.
  • Create new PDF documents or modify existing PDF documents.
  • Add content onto existing or new pages.
  • Assemble documents, split, merge, combine documents, remove pages.
  • Encrypt documents using RC4 or AES encryption, set document permissions.
  • Set and get interactive form field data.
  • Convert documents to JPEG, PNG images.
  • Extract text content.
  • Digital Signatures, apply new signatures or verify existing signatures
  • Edit document properties such as title, keywords, subject.

Getting Started

Download and install qPDF Toolkit in your developing environment.

Once you have installed these files, you should be able to start coding with the toolkit. Please refer to our Source Code Samples to see some simple source code that you can use to test that your development environment is setup correctly.

Create a New Document

when working with PDF documents, the central class that will be used is called PDFDocument, the class is located in the com.qoppa.android.pdfProcess package. This class represents a PDF document and can be used to load an existing document and to create new documents as well.

To create a new document takes one line of code:

PDFDocument pdf = new PDFDocument();

Once you have created a PDFDocument object, content can be added by adding pages from other documents and content can be drawn onto existing pages, or onto new blank pages. Please refer to one of our code samples to get started creating documents:

CreatePDF.java

Modify an Existing Document

To modify an existing document works very much like creating a new document. First, a document is loaded into a PDFDocument object:

PDFDocument pdf = new PDFDocument ("/sdcard/input.pdf", null);

Once loaded, content can be added to the document the same way as for a new document, pages can be deleted, or added from other documents, content can be drawn onto existing or new blank pages, fields modfied, and more.

Please refer to the following source code sample for reference:

AddContentToPDF.java

QPDFViewerView

As part of the toolkit, there is a class called QPDFViewerView, which is an extensions of FrameLayout and can be included in an app by adding as a View in an Activity. This view is a complete implementation of a PDF viewer, based on the toolkit.

the intent of this class is to provide a near complete PDF viewer, that is configurable through the API, that you can quickly add to your own Android app to let your users display and navigate PDF documents.

A simple activity that includes the view would look like this:

public class ViewSample extends Activity {
  public void onCreate(Bundle saveInstBundle) {
    super.onCreate(saveInstBundle);
 
    QPDFViewerView viewer = new QPDFViewerView (this);
    viewer.setActivity(this);
 
    setContentView(viewer);
  }
}

A couple of tips:

– The application toolbar can be accessed with QPDFViewerView.getToolbar(). It can be customized with things like:

QPDFViewerView.getIbOpen().getParent().remove(QPDFViewerView.getIbOpen());

– You can prevent the Views from being destroyed on device rotation by adding this to your activity’s tag in your AndroidManifest.xml:

android:configChanges="keyboardHidden|orientation|keyboard"

– You can forward the configuration event to QPDFViewerView and it will restore the previous scroll location by adding this to your activity:

@Override
public void onConfigurationChanged(Configuration newConfig) {
  super.onConfigurationChanged(newConfig);
  m_Viewer.onConfigurationChanged(newConfig);
}

QPDFNotesView

As part of the toolkit, there is also a class included called QPDFNotesView that extends an Android View. This class can be used within your application to show PDF documents and also provides annotation tools, similar to our qPDF Notes app.

Here is a sample activity that uses the view:

public class ViewSample extends Activity {
  public void onCreate(Bundle saveInstBundle) {
    super.onCreate(saveInstBundle);
 
    QPDFNotesView viewer = new QPDFNotesView (this);
    viewer.setActivity(this);
 
    setContentView(viewer);
  }
}

A couple of tips:

– The application toolbar can be accessed with QPDFNotesView.getToolbar(). It can be customized with things like:

QPDFNotesView.getIbOpen().getParent().remove(QPDFNotesView.getIbOpen());

– You can prevent the Views from being destroyed on device rotation by adding this to your activity’s tag in your AndroidManifest.xml:

android:configChanges="keyboardHidden|orientation|keyboard"

– Also, you can forward the configuration event to QPDFViewerView and it will restore the previous scroll location by adding this to your activity:

@Override
public void onConfigurationChanged(Configuration newConfig) {
  super.onConfigurationChanged(newConfig);
  m_Notes.onConfigurationChanged(newConfig);
}

Obfuscate with ProGuard

In order to obfuscate your application, add the following to your ProGuard configuration file:

-libraryjars (path to jar)/js-14.jar
 
-dontwarn org.apache.**
-dontwarn com.qoppa.**
-keep class com.qoppa.** { *; }
-keep class org.mozilla.** { *; } 
-dontwarn org.mozilla.**
-keep class com.qoppa.notes.javascript.* 
{
    public ;
}

Note: js-14.jar contains classes needed for supporting JavaScript in Acroforms.