Using thumbnail browser to manipulate PDFs in Android

The ThumbnailsViewFragment class allows users to manipuate pages of a document including add, remove, re-arrange, rotate and duplicate pages. Users are also able to undo/redo page manipulations.

Apryse Docs Image

Show page thumbnails dialog

To show a page thumbnails dialog in your activity, create a new instance of ThumbnailsViewFragment by calling newInstance() and setting the PDFViewCtrl:

1private PDFViewCtrl mPdfViewCtrl;
2// ...
3public void showThumbnailsFragment(FragmentManager fragmentManager) {
4 ThumbnailsViewFragment fragment = ThumbnailsViewFragment.newInstance();
5 fragment.setPdfViewCtrl(mPdfViewCtrl);
6 // Show the dialog
7 fragment.show(fragmentManager, "thumbnails_view_dialog");
8}

If you want to specify that the document is read-only you can use newInstance(boolean):

1ThumbnailsViewFragment fragment = ThumbnailsViewFragment.newInstance(true);

Export pages

If you would like to allow users to export a subset of pages from the document, you should implement OnExportThumbnailsListener interface by providing implementation for exporting pages:

1fragment.setOnExportThumbnailsListener(new ThumbnailsViewFragment.OnExportThumbnailsListener() {
2 @Override
3 public void onExportThumbnails(SparseBooleanArray pageNums) {
4 // Implementation for exporting given pages.
5 }
6});

If you set OnExportThumbnailsListener, the "Export" menu item will show up in the overflow menu when at least one page is selected.

Apryse Docs Image

Dialog callbacks

If you want to be notified when the thumbnails view dialog fragment is dismissed, implement OnThumbnailsViewDialogDismissListener interface. Also, if you want to be notified when the user attempts to edit pages while the document is read only you should implement OnThumbnailsEditAttemptWhileReadOnlyListener interface:

1fragment.setOnThumbnailsViewDialogDismissListener(new ThumbnailsViewFragment.OnThumbnailsViewDialogDismissListener() {
2 @Override
3 public void onThumbnailsViewDialogDismiss(int pageNum, boolean docPagesModified) {
4 // Handle viewer when the thumbnails view dialog is dismissed.
5 // For example, update the page numbers etc.
6 }
7});
8fragment.setOnThumbnailsEditAttemptWhileReadOnlyListener(new ThumbnailsViewFragment.OnThumbnailsEditAttemptWhileReadOnlyListener() {
9 @Override
10 public void onThumbnailsEditAttemptWhileReadOnly() {
11 // Show message when user attempts to edit pages of a read only document.
12 Toast.makeText(activity, "Read-Only document", Toast.LENGTH_SHORT).show();
13 }
14});

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales