For the complete documentation index, see llms.txt. This page is also available as Markdown.

Display documents in Fragment with Apryse Android SDK

All actions related to the PDF viewer are handled through the PdfViewCtrlTabHostFragment2. This fragment extends androidx.fragment.app.Fragment and is responsible for showing documents in tabs.

Prerequisites

No trial license key required.

The trial of Apryse Mobile SDK does not require a trial key. A commercial license key is required for use in a production environment. Please contact sales to purchase a commercial key or if you need any other license key assistance.

Step 1: Update AndroidManifest.xml

  1. In order to support all the features in PdfViewCtrlTabHostFragment2, we will need to add the Android permissions listed in this table. However if you would like to disable certain features and customize your document viewer, you should leave out unnecessary permissions.

  1. Enable largeHeap, usesClearTextTraffic, and set android:name in the <application> tag to MultiDexApplication:

  1. Declare your activity in the manifest file:

Note that your activity must extend AppCompatActivity.

  1. If you have not done so already, add the <meta-data> tag containing a reference to your license key in the AndroidManifest.xml file. The final AndroidManifest.xml file should look something like this:

Step 2: Launch the viewer

Use ViewerBuilder2 to create an instance of PdfViewCtrlTabHostFragment2, and add it to your activity layout. To add a document viewer fragment for a given password-protected file, call the following method in your activity:

where fragmentContainer is the resource id of a layout in your activity that will contain your fragment:

For example:

Alternatively if you have extended PdfViewCtrlTabFragment2 or PdfViewCtrlTabHostFragment2, you can specify your custom classes using the ViewerBuilder2.usingTabClass() method and the ViewerBuilder2.build() method as follows:

Since Apryse uses the Fragment class from the Support Library, your activity must extend AppCompatActivityand call getSupportFragmentManager() to get the FragmentManager.

Step 3: Customize the viewer

Customize document viewer style

  • If you would like to customize the appearance of the viewer activity, define PDFTronAppTheme in styles.xml:You can learn more about this in the customize the viewer's theme guide .

PdfViewCtrlTabHostFragment2 uses the AppCompat theme for material colors. Make sure that the value of android:theme in your activity tag also extends the AppCompat theme.

Customize using ViewerConfig

  • If you would like to customize certain viewer settings or the UI of PdfViewCtrlTabHostFragment2, you can use ViewerConfig.Builder. For example:

For details on customizing the UI and using ViewerConfig.Builder, check out the configuration tutorial .

Customize the options toolbar

The default toolbar menu consists of the following buttons on phones:

  • App navigation

  • Toolbar switcher

  • Tab switcher

  • Overflow menu

The default toolbar menu consists of the following buttons on tablets:

  • App navigation

  • Toolbar switcher

  • Document text search

  • View mode configuration

  • Thumbnails browser

  • List container

  • Overflow menu

You can fully customize the toolbar menu and the navigation icon by calling the following in ViewerBuilder2, with custom menu resource and drawable resource files:

To change the icon color and overflow icon color, in styles.xml:

To change the navigation icon color, in styles.xml (assume MyTheme is used as the app theme):

Step 4: Interact with the fragment

If you would like to interact with the host fragment you can call addHostListener(TabHostListener) and override the methods that you are interested in. For example, you may want to override onToolbarOptionsItemSelected(MenuItem) when you add a new menu item, so when the item is clicked you can get a callback. As another example, you can get the callback when the navigation icon is clicked if you override onNavButtonPressed().

Here's an example that replaces the default navigation icon and uses a custom toolbar:

where ic_arrow_back_white_24dp.xml is a drawable resource file for a back arrow icon, and my_custom_toolbar.xml is a menu resource file that contains:

This sample replaces the navigation icon, removes all toolbar buttons except the annotation toolbar button, and adds a new Show Toast button:

Last updated

Was this helpful?