Best Android PDF Libraries 2018

May 20, 2018 Oclemy Android PDF 3 minutes, 49 seconds

Best Android PDF Libraries 2018

PDF stands for Portable Document Format. It's a file format developed in the 1990s to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems.

PDF was first released 24 years ago in the year 15 June 1993 by Adobe, however is now an open standard maintained by the International Organization for Standardization (ISO).

There are plenty of free and commercial PDF Reader applications for android devices. However, we as developers should build our own little pdf readers that maybe we and our friends can use.

It's not as difficult as you would think and several open source libraries exist to aid in this.

In this piece we will look at some of these libraries and probably snippets of how to use them.

Let's start.

1. AndroidPdfViewer

This is an open source libary for displaying PDF documents.These PDFs are rendered with PdfiumAndroid.

AndroidPdfViewer is currently the most popular Android PDF View library. It's maintained by bartesk and he has released various versions of the library independently.

For example, alot of people are still using AndroidPdfView, yet there is a AndroidPdfViewV1 and AndroidPdfViewV2.

This library has support for animations, gestures, zoom and double tap support.

Using this library is easy, very easy.

First you just include it in your app level build.gradle:

compile 'com.github.barteksc:android-pdf-viewer:2.8.2'

Then in your layout:


Then you can load the pdf from various sources:

pdfView.fromStream(InputStream) // stream is written to bytearray - native code cannot use Java Streams
    .pages(0, 2, 1, 3, 3, 3) // all pages are displayed by default
    .enableSwipe(true) // allows to block changing pages using swipe
    // allows to draw something on the current page, usually visible in the middle of the screen
    // allows to draw something on all pages, separately for every page. Called only for visible pages
    .onLoad(onLoadCompleteListener) // called after document is loaded and starts to be rendered
    .onRender(onRenderListener) // called after document is rendered for the first time
    // called on single tap, return true if handled, false to toggle scroll handle visibility
    .enableAnnotationRendering(false) // render annotations (such as comments, colors or forms)
    .enableAntialiasing(true) // improve rendering a little bit on low-res screens
    // spacing between pages in dp. To define spacing color, set view background
    .invalidPageColor(Color.WHITE) // color of page that is invalid and cannot be loaded
View Download
View Direct Download

2. PdfiumAndroid

The same author of AndroidPdfViewer, bartesk forked PdfiumAndroid from it's original repository and has been maintaining and added some documentation as well.

The original PdfiumAndroid hasn't been maintained.

So the [forked version(] has some documentation and is being actively mainatinaed.

He forked it so as to use it with the popular AndroidPdfViewer.

However you can use it independently as well.

First you'd need to add it as a dependency:

compile 'com.github.barteksc:pdfium-android:1.8.2'

Then here's a simple example:

void openPdf() {
    ImageView iv = (ImageView) findViewById(;
    ParcelFileDescriptor fd = ...;
    int pageNum = 0;
    PdfiumCore pdfiumCore = new PdfiumCore(context);
    try {
        PdfDocument pdfDocument = pdfiumCore.newDocument(fd);

        pdfiumCore.openPage(pdfDocument, pageNum);

        int width = pdfiumCore.getPageWidthPoint(pdfDocument, pageNum);
        int height = pdfiumCore.getPageHeightPoint(pdfDocument, pageNum);

        // ARGB_8888 - best quality, high memory usage, higher possibility of OutOfMemoryError
        // RGB_565 - little worse quality, twice less memory usage
        Bitmap bitmap = Bitmap.createBitmap(width, height,
        pdfiumCore.renderPageBitmap(pdfDocument, bitmap, pageNum, 0, 0,
                width, height);
        //if you need to render annotations and form fields, you can use
        //the same method above adding 'true' as last param


        printInfo(pdfiumCore, pdfDocument);

        pdfiumCore.closeDocument(pdfDocument); // important!
    } catch(IOException ex) {

public void printInfo(PdfiumCore core, PdfDocument doc) {
    PdfDocument.Meta meta = core.getDocumentMeta(doc);
    Log.e(TAG, "title = " + meta.getTitle());
    Log.e(TAG, "author = " + meta.getAuthor());
    Log.e(TAG, "subject = " + meta.getSubject());
    Log.e(TAG, "keywords = " + meta.getKeywords());
    Log.e(TAG, "creator = " + meta.getCreator());
    Log.e(TAG, "producer = " + meta.getProducer());
    Log.e(TAG, "creationDate = " + meta.getCreationDate());
    Log.e(TAG, "modDate = " + meta.getModDate());

    printBookmarksTree(core.getTableOfContents(doc), "-");


public void printBookmarksTree(List<PdfDocument.Bookmark> tree, String sep) {
    for (PdfDocument.Bookmark b : tree) {

        Log.e(TAG, String.format("%s %s, p %d", sep, b.getTitle(), b.getPageIdx()));

        if (b.hasChildren()) {
            printBookmarksTree(b.getChildren(), sep + "-");
View Download
View Direct Download

Best Regards.