How do I load and view a PDF file in my app?

533 views Asked by At

I've tried…

  1. webview + google docs viewer

  2. PdfRenderer

…but each of them has an issue:

  1. is stable but can't change landscape mode. and can't choose initial page.

  2. can choose initial page, and landscape mode, but it's very slow. and low resolution.

Does anyone know of any better options?

1

There are 1 answers

0
CommonsWare On

it should be open with in app

Frequently, that is not what the user wants.

Beyond that, quoting myself:

The PDF renderer that Mozilla uses for Firefox is PDF.js. This works with Android's WebView, but only the modern incarnation of WebView (i.e., Android 4.4+). It will also add ~2MB to your APK file, in the form of a few MB of JavaScript that you need to package as assets. But, it can handle a fairly wide range of PDF files.

The PDF renderer that Google uses for Chromium is pdfium. However, this is C/C++ code, not JavaScript. Bartosz Schiller's AndroidPdfViewer library wraps Pdfium in a View that handles rendering and standard gestures (e.g., horizontal swipes to move between pages). This works well on older Android versions (I tested through 4.1), but it adds about 5MB to your APK per CPU architecture. By default, you get six architectures and 30MB of overhead. With careful pruning of unnecessary CPU support (see ya, MIPS) and ABI splits, you can minimize the per-APK footprint, but you wind up with greater deployment complexity.