• 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

After downloading the qpdftoolkit.zip file from our download page, uncompress the contents of the archive to a folder. The file contains four items:

version_history.txt – This text file will be updated with each new version of the toolkit.

qoppapdf.jar – This is the main jar file for the toolkit. Include this jar as a 3rd party library for your android project by adding it to the project’s libs folder (with newer versions of the ADT plugin, it is not necessary to manually add the jar to your project’s classpath).

    • Adding the 3rd party library may cause eclipse to crash due to out of memory exceptions. This can be fixed by modifying the vmargs in the eclipse.ini file to increase memory available to eclipse. An example of vmargs that work when using the third party jar:
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Dhelp.lucene.tokenizer=standard
-Xms512m
-Xmx1024m
-XX:+UseParallelGC
-XX:PermSize=256M
-XX:MaxPermSize=512M

assets folder – This folder contains assets used by the toolkit, such as fonts and icons. The file contents of this folder should be copied to the assets folder in your project.

libs folder – This folder contains native Android libraries, these libraries are needed to decode certain JPEG images as well as JPEG 2000 images that are not supported by Android. The contents of the libs folder need to be copied to the libs folder in your project. If you don’t have a libs folder in your project, create one and copy the contents of this folder into it.

Once you have installed these files into your development environment, 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

The sdk includes classes from js-14.jar because we intend to support javascript in acroforms in the future, though it is currently inactive. In order to obfuscate your application, download the jar and 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 <methods>;
}