Creating PDFs on Android – an evaluation

Together with Michael Schöner we evaluated 14 Java PDF libraries regarding their Android compatibility. 3 of 14 evaluated libraries were compatible with Android and allowed us to create PDFs on the Android platform.

Introduction

This work describes the capability of creating PDF Documents including graphics on android driven appliances. For this purpose, 14 Java PDF libraries are tested and evaluated with the aid of the Android SDK and its debugging tools. The main focus of the evaluation lies on easy integration into the Android environment but also CPU, memory and time consumption. Besides the technical characteristics, many other aspects of the libraries are presented like provided documentation, license, update cycle, etc.

Evaluation method

Pre-evaluation: First, the library is checked for its functionality. If it does not support the insertion of text and images no further evaluation is done. In a second step we integrated the library in a test program, which should create a PDF file including text and an image. If this step succeeds, a detailed evaluation was conducted as described in the following.

Resource utilization

  • memory consumption
  • processor utilization
  • time consumption

Although hardware components for mobile devices are getting more and more powerful, it is still necessary to optimize software for such devices. The main reason for decreasing the file size, the processor utilization and the time consumption is to save battery capacity but also the user experience will be better. Smaller file size speeds up the download and installation of the application, better algorithms and/or well chosen libraries can drastically reduce processor load and execution time. All these factors preserve the battery.

Usability

  • documentation
  • provided examples
  • effort required for integration on android / complexity
  • offered functionality

The more examples and documentation are available the higher the chance to find code parts that help to implement the own application. Because the integration of Java libraries on Android is not always straightforward, a library that is easy to integrate reduces time of development. Also the offered functionality should be concerned before choosing a library to have the possibility to provide update versions of the own program with more features.

General

  • manufacturers
  • license
  • open source / closed source
  • vitality of the software project
  • community / forums / literature

Depending on the project, a certain license of the used library can be mandatory. When developing a commercial, closed source program, some open source libraries cannot be used because of their specific license. In case of writing applications for academic purposes often open source licenses are preferred because of the possibility to read the source code for a deeper understanding of certain functions and the possibility to adapt even the library itself. In addition, most open source libraries can be used at no cost for non commercial projects.

Also the manufacturer and the vitality of the library project is of interest, is it a big company that will probably exist also in many years or, e.g. a project of only one developer. Regular update cycles indicate that the library is still maintained and enhanced. And the bigger and vital the libraries’ community the better the chances of getting help in case of difficulties to implement the library. That means looking for forums, mailing lists or even a written book of documentation can help to decide for the right candidate.

Pre-Evaluation

The following Java PDF libraries are tested for functionality on Android platform:

  • PDF Box
  • FOP
  • jPod
  • gnujpdf
  • PDFjet
  • iText
  • JFreeChart
  • PJX
  • JPedal
  • PDF Clown for Java
  • PDF Renderer
  • Qoppa qPDF Toolkit
  • BFO
  • PDFOne

For each PDF library an own class is created to encapsulate the library specific preparation of text, images and creation of PDF files. The creation of the PDF is directly done in the constructors of the PDF library classes. The Android Resource class “R” contains an example text and a test image for integration into the PDF. The main class “AndroidPDFTest” loads the text and image and opens an output stream for saving the PDF file. Then it calls the method “createPDF” of the PDF library wrapper class, which distributes the call to the current defined PDF library class.

The testing is done against Android 3.1 and Android 2.3.3.
Android version: 3.1, API level 12
Android version: 2.3.3, API level 10
Eclipse version: 3.6.1, Helios
Development platform: Linux SuSE 11.4, kernel 2.6.37

inappropriate incompatible working libraries
FOP, JFreeChart PDF Box, jPod, gnujpdf, PJX, JPedal, PDF Clown, BFO, PDF Renderer iText, Quoppa qPDF Toolkit, PDFJet

Nearly all tested libraries provide the insertion of text and images to PDF documents but only three of them run on Android devices. In the following section we present our detailed evaluation results regarding the Android-compatible libraries.

Evaluation Results

Resource utilization

An exact determination of memory usage of running processes is not possible because many parts of memory are shared between several processes, so there is no way to correlate this shared memory to a specific process. For the determination of the memory usage the Android shell command procrank is used. This command shows the previous described memory usage (PSS: shared memory, divided evenly between the processes that share it; USS: memory that is unique to a process) for all running processes.

The time consumption for the PDF document creation is determined with the Android Tool traceview. For this purpose the Android Debug class is used in the source code to mark the start and the endpoint of the measurement. When the application runs, a trace file is created which can be evaluated with traceview. This tool is not only suitable for time measurements, it also shows which methods are called and their execution time.

The CPU utilization is measured with the Android shell command top. Similar to common Linux systems, it shows informations about the most active processes like CPU consumption, process owner, process id and also memory usage.

The results are very distinctive apart from the memory usage. The iText application has a larger file size but stands out in nearly all other disciplines. The most significant difference is the time consumption, the PDF creation is more than 10 times faster as with the other applications. But also the CPU utilization of the iText application is lower compared to the CPU usage of the competitors.

Performance evaluation results

iText

  • Application file size: 1.48 MB
  • Time consumption for creating the PDF document: 3.7 ms
  • Average CPU utilization: 29%
  • Maximum CPU utilization: 81%
  • Memory usage USS (maximum): 17.5 MB
  • Memory usage PSS (maximum): 19.5 MB

Qoppa qPDF Toolkit

  • Application file size: 0.93 MB
  • Time consumption for creating the PDF document: 39 ms
  • Average CPU utilization: 77.9%
  • Maximum CPU utilization: 94%
  • Memory usage USS (maximum): 15.7 MB
  • Memory usage PSS (maximum): 17.3 MB

PDFJet

  • Application file size: 0.67 MB
  • Time consumption for creating the PDF document: 51.3 ms
  • Average CPU utilization: 86.8%
  • Maximum CPU utilization: 94%
  • Memory usage USS (maximum): 18.9 MB
  • Memory usage PSS (maximum): 20.4 MB

Usability

The usability of all 3 libraries is excellent. The creation of PDF files including images and text is straight forward at a high abstraction level, no need to struggle with the PDF specific low level structure. All of the libraries provide a Javadoc API reference describing the containing classes and their methods.

The number of available example programs is very differing, 3 for Qoppa, 20 for PDFJet and a countless number of examples for the iText library, all used in the iText book.

While the PDFJet library offers the most common features for creating PDF documents, iText and Qoppa provide more possibilities like password protection, extracting text from PDF files, modifying existing documents, form manipulation and more. Qoppa is the only software that supports rendering PDF files to images and canvas objects, in this manner it is very easy to implement a PDF viewer.

iText
Documentation: Javadoc
Provided examples: a huge number of examples are available
Effort required for integration on android: very easy, 9 lines of code for the PDF creation
Functionality offered:

  • create PDF documents
  • modify PDF documents
  • drawing support for several shapes like circle, polygons, etc.
  • encryption, password protection
  • set and get interactive form field data
  • extract text content
  • helper classes for tables and bar codes

Qoppa qPDF Toolkit
Documentation: Javadoc
Provided examples: only 3 samples are provided
Effort required for integration on android: very easy, 9 lines of code for the PDF creation
Functionality offered:

  • create PDF documents
  • modify PDF documents
  • drawing support for several shapes like circle, polygons, etc.
  • encryption, password protection
  • set and get interactive form field data
  • convert PDF to JPG or PNG images
  • render pages to Bitmap or Canvas objects
  • extract text content

PDFJet
Documentation: Javadoc included in source package
Provided examples: 20 examples included in source package
Effort required for integration on android: very easy, 14 lines of code for the PDF creation
Functionality offered:

  • create PDF documents
  • drawing support for several shapes like circle, polygons etc.
  • helper classes for tables, charts and bar codes

General

The surrounding resources of the iText project are outstanding. It’s the only library that can provide a complete book which describes the functionalities of the library in detail and which also contains many example programs. Also, none of the other projects provide a forum or a mailing list but iText does. The Qoppa project offers a knowledge base, which contains additional information about the library.

iText and PDFJet have both a commercial and an open source license. This has 2 advantages: First, the user of the library can choose which license fits best for his program, e.g. for a non commercial project the open source license can be used at no cost. At the other hand, because there is an open source license the source code of the library is available, which can be very useful for a deeper understanding of certain processes. The Qoppa project has a commercial license only, the source code is not available.

All of the projects are well maintained, there is no release version older than 4 months.

iText
Manufacturer: iText Software Corp.
Project website: http://itextpdf.com/
Philosophy: Open source project
Licenses: Affero General Public License or commercial license
Current version: 5.1.2 published 2011-08-15
Number of version updates last 12 months: 6
Books: 1
Forums: 1
Mailing lists: 1

Qoppa qPDF Toolkit
Manufacturer: Qoppa Software
Project website: http://www.qoppa.com/android/pdfsdk/index.html
Philosophy: Closed source project
Licence: commercial license
Current version: 1.0 published 2011-05-23
Number of version updates last 12 months: not available
Books: 0
Forums: 0
Mailing lists: 0

PDFJet
Manufacturer: Innovatics Inc.
Project website: http://pdfjet.com/java/index.html
Philosophy: Open source project
Licences: Open Source Edition License or commercial license
Current version: 2.85 published 2011-06-12
Number of version updates last 12 months: 5
Books: 0
Forums: 0
Mailing lists: 0

Conclusion

This evaluation shows that the implementation of applications for creating PDF documents on Android platform is rather simple and there are at least 3 PDF libraries which help to create such applications: iText, Qoppa and PDFJet. These libraries are evaluated in resource utilization, usability and some surrounding conditions like available documentation, license and more. For the measurement of the used system resources a simple test application is implemented. Depending on the requirements, each library has its benefits and handicaps (see the following table for an overview). The iText library provides many features and the best performance, only the resulting application file size is a disadvantage. The outstanding feature of the Qoppa library is the possibility to render a PDF to an image which makes it very easy to build an integrated PDF viewer. PDFJet wins in the file size competition but has the smallest feature list compared to iText and Qoppa.

iText Qoppa PDFJet
application file size 1.48MB 0.93MB 0.67MB
time consumption 3.7ms 39ms 51.3ms
average CPU utilization 29% 77.9% 86.8%
modification of PDFs yes yes no
encryption yes yes no
form field functions yes yes no
text extraction yes yes no
converting PDF to images no yes no
open source yes no yes
book available yes no no
forum, mailing list yes no no

Recommendation

Although all 3 libraries provide many features and are easy to apply, the advantages of the iText library are outstanding:

If a minimal application file size is not the highest priority the iText library should be used. Besides the rich features of this library, it has the best condition for obtaining support (book, mailing list and forum). Also, it can be integrated at no cost as long the resulting application is open source and non commercial.

The Qoppa library is recommended only, if you need to implement an integrated PDF viewer in your application.