Reducing the library file size for mobile apps

Q:

We would like to use PDFNet for our mobile apps. I have a question re: file size. When I build PDFNet viewer Android sample the APK file is fairly large (~20+ MB). Can PDFTron libs be compressed? What are our options here?

A:

There are some things that you can do on your end to keep the app size under 10M. If you require even further reduction we could trim away some rarely used resources to bring down the file size to ~5MB (as part of a custom build). The following section describes the situation on iOS and Android in more detail:


iOS: The current version of libPDFNet.a is over 100 MB, however this will not increase the size of your app by anywhere close to 100 MB. This is a fat, universal library and contains complete object code for three architectures: i386 for the simulator, armv7 for devices and armv7s for devices that use the A6/A6X, each of which contribute about a third of library’s total size. If you build for armv7 only (which will run on all modern devices, including the ones that use an A6(X)), then it will include only code for that one architecture, and because it’s a static library, it will only include the portions of it that it actually uses. In this case PDFNet will normally add about 9 MB to your app, depending on what PDFNet classes you use.

Android: The prebuilt APK includes libraries for both arm v6 and v7. When the apk is installed, Android selects the right library based on the device’s architecture. You can technically remove either of the two folders (libs/armeabi or libs/armeabi-v7a) in the sample project. The armeabi folder contains the .so file for devices with only arm v6 support, while armeabi-v7a folder contains the .so file for devices with arm v7 support (v6 library will run on v7 devices but may not take advantage of all optimizations). If you don’t need to support v6 devices you can remove v7 library. If you just need to support v7 devices, you can keep v7 and remove v6 lib. If you keep both, Android will install the proper one based on the arm structure of the device. In case you are deploying you app via Google Play, you can use “Multiple APK Support” (http://developer.android.com/guide/google/play/publishing/multiple-apks.html). The basic idea is to generate separate APKs using either the .so file for arm v6 (libs/armeabi) or the .so file for arm v7 (libs/armeabi-v7a) to have smaller APKs and then publish them as being the same app in Google Play. With this schema, Google Play will automatically identify which APK to install based on the device’s architecture.


As mentioned before, if 9 MB still sounds too large, then as part of a custom project we could reduce the app size to ~5 MB by removing functionality and downloading certain resources on demand (such as extra font packs, CMaps, etc.) rather than including them as a default.

Note:

PDFNet for Android is now available in a new standard feature reduced variant (a.k.a. ‘lean’). The lean library offers the same viewing, annotation, and editing capabilities of the fully featured library however it is half the size (6MB uncompressed!). The parts that are missing are relatively rarely used components (such as Redaction, ContentReplacer, Optimizer, Flattener, and Converters). You can request a trial at the following page http://www.pdftron.com/pdfnet/mobile/request_trial.html

If your APK is large even with the lean library, you may be packaging multiple SO files in the same APK. If the file size is issue you can use ‘Multiple APK’ feature to let the user download the right SO version instead of having to bungle all architectures in a single package.

We can provide even smaller custom build variants but keep in mind that just standard PDF resources take at least 3MB so there may not be much to gain with further reductions.