Blog Post

PSPDFKit 2.6 for Android

Illustration: PSPDFKit 2.6 for Android

PSPDFKit continues its saga on Android with the 2.6 release of PSPDFKit for Android and a host of new features and improvements! In this post, we outline the most mentionable features of the release. If you want to try all the new features right away, download our free PDF Viewer app.

Stamp and image annotations

Two of the most demanded annotation types found its way to Android: The StampAnnotation and its cousin the image annotation. Both are now fully supported via API and user interface. To create them, select the annotation type from the toolbar and tap on the PDF document. This will bring up the stamp picker or an image chooser (depending on the selected annotation tool).

Stamp annotation

Creating a StampAnnotation from code works just like with any other annotation type. The StampAnnotation has constructors that can take a predefined StampType, or even a Bitmap object that was loaded from an image file.

final Bitmap bitmap = BitmapFactory.decodeStream(context.getAssets().open("custom_image.jpg"));
final StampAnnotation stampAnnotation = StampAnnotation(0, new RectF(210f, 520.0f, 410.0f, 330.0f), bitmap);
document.getAnnotationProvider().addAnnotationToPage(stampAnnotation);

Material design sharing menu

The new ActionMenu is a bottom sheet dialog as described by the material design guidelines. Based on that class, the SharingMenu shows apps that are able to share the current PDF document (usually messaging apps, email clients, etc.). The specialized DefaultSharingMenu adds two more fixed actions for printing or opening the PDF document in another app. The new menu classes are available via the public API, and also used by the PSPDFActivity when tapping the share action. If you’re interested in customizing the sharing menu, the CustomSharingMenuExample inside the catalog app is a good starter for you.

Stamp annotation

Tiled rendering

PSPDFKit 2.6 for Android ships with a new page renderer, used to display pages on the PSPDFFragment. The renderer utilizes image tiling, which greatly improves rendering times while also reducing memory requirements and churn rates. An on-screen page is split up into several bitmaps, each of the same size. This allows a very effective bitmap reuse, better pooling, and paves the way for future higher-level rendering features like partial rendering of damaged regions. The new renderer also eliminates blurred text while zooming, which haunted previous versions of PSPDFKit for Android. We are very happy about the progress we made so far and will continue improving this central component of our framework in the upcoming versions.

Better organized toolbars with submenus

We spend a lot of time improving the usability of our existing toolbars API and added contextual submenus. Any action that offers a second-level menu can show a small submenu indicator next to its icon. Long-pressing the action will reveal the submenu next to the main toolbar. This results in a much simpler to understand and thus better toolbar flow than we had in previous versions.

Submenus via long-press gesture

Since the new submenus use the existing ContextualToolbarMenuItem#setSubMenuItems method, there are no code changes required if you are using this feature in code.

Document downloads made easy

PSPDFKit for Android 2.6 adds a convenient download job API that allows you to retrieve PDF files that are not available on the local file system. For example, you can use the API for downloading PDF documents from a third-party content provider, or use it to extract a file from the assets of your app. You can also define custom download sources by implementing the DownloadSource interface.

To initiate a download you first build a DownloadRequest and pass it to DownloadJob#startDownload(DownloadRequest) method. The returned DownloadJob provides methods for observing the progress or canceling it. Also, it stores as a single object for retaining the download across configuration changes. Our new document download API guide shows how to do this.

final DownloadRequest request = new DownloadRequest.Builder(context)
    .uri("content://com.example.app/documents/example.pdf")
    .outputFolder(context.getDir("documents", Context.MODE_PRIVATE))
    .overwriteExisting(false)
    .build();

final DownloadJob job = DownloadJob.startDownload(request);

job.setProgressListener(new DownloadJob.ProgressListenerAdapter() {
    @Override public void onProgress(@NonNull Progress progress) {
        updateProgressUi(progress);
    }

    @Override public void onComplete(@NonNull File output) {
        useDownloadedFile(output);
    }
});

Check out the catalog app: We have updated the omnipresent ExtractAssetTask, which now also uses this new download API for extracting demo assets.

Analytics for PSPDFKit

For all of you that strive to get the most out of your user data, we added a small but powerful analytics API. By adding an AnalyticsClient instance using PSPDFKit#addAnalyticsClient you can receive several otherwise hard to extract user-triggered events. Among those events are:

  • Actions on annotations (selection, creation, editing, and deleting).

  • Navigation events (page changes, bookmarks, links, etc.).

  • Bookmark usage (adding, editing, sorting, …).

  • And many more!

For a complete list of available events have a look at the Analytics.Event class.

By default the analytics API is deactivated and does not collect any data by itself. Also, it does not send any data out of the app: this is responsibility of your app when using this API. In general, PSPDFKit never collects your user's information. More information can be found in our SDK security guide.

Document cache invalidations

We’ve seen demand for better cache handling so we added methods to invalidate render caches for a single document or page. In addition to the already existing PSPDFKit#clearCaches method, you can now call PSPDFKit#invalidateDocumentCache or PSPDFKit#invalidatePageCache passing in the affected document instance and page index. Use this method whenever your application modifies the PDF document externally and you want to let PSPDFKit re-render the modified content.

final PSPDFDocument changedDocument = ...;
PSPDFKit.invalidateDocumentCache(context, changedDocument, true);

Many more improvements

  • If your app relied on triggering the annotation creation mode manually, we updated the API for you: It is now possible to choose different creation modes that use the same annotation type. To do so, we introduced the AnnotationCreationMode and a method PSPDFFragment#enterAnnotationCreationMode(AnnotationCreationMode). The old method, taking an AnnotationType still exists in this version, but was deprecated and will be removed in a future update.

getPSPDFFragment().enterAnnotationCreationMode(AnnotationCreationMode.IMAGE);
  • The new DocumentSource is a unified object for describing the source of a document. It can be constructed from either a Uri or a DocumentProvider. We added methods to the PSPDFKit class for opening documents using the DocumentSource.

  • Examples say more than 1000 words, so we updated our guides and added several new examples to the catalog app. The CustomSharingMenuExample shows how to add custom share actions to the sharing menu of a PSPDFActivity. The DocumentProcessorExample has been extended, now showcasing how to rotate pages and how to add pages using the PSPDFProcessor. And the DocumentDownloadExample describes how to use our new downloader API.

If you’d like to explore all the improvements we made in this release, have a look at our full list of changes in PSPDFKit 2.6 for Android or try out our PDF Viewer App for Android - currently in beta and free.

Explore related topics

Related products
Share post
Free trial Ready to get started?
Free trial