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.
Keep your license keys confidential.
License keys are uniquely generated. Please make sure that it is not publicly available (e.g. in your public GitHub).
Step 1: Update AndroidManifest.xml
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.
Storage permission
Please note that from Android 6.0 (API 23) and up, applications need to request storage permission at runtime before accessing any files on device.
If your app is targeting Android SDK version 28 or higher, you will need to add the android:usesCleartextTraffic="true" attribute in your application tag to open HTTP files in the viewer. If you are only working with HTTPS files, this is not required.
Define your Activity to extend AppCompatActivity and use an AppCompat theme:
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:
C#
1// Add a viewer fragment to the layout container in the specified activity,
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:
C#
1// Add a viewer fragment to the layout container in the specified activity,
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:
C#
1public PdfViewCtrlTabHostFragment2 createUsingViewerConfig(Context context, Uri fileUri, String password)
2 {
3 // Create a ViewerConfig object with custom settings
4 var config = new ViewerConfig.Builder()
5 .FullscreenModeEnabled(true)
6 .MultiTabEnabled(true)
7 .DocumentEditingEnabled(true)
8 .LongPressQuickMenuEnabled(true)
9 .ToolbarTitle("Host Fragment")
10 .ShowSearchView(true)
11 .Build();
12
13 // Pass in the ViewerConfig object into the ViewerBuilder2
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:
C#
1public PdfViewCtrlTabHostFragment2 createUsingCustomToolbar(Context context, Uri fileUri, int navIcon, int[] menuRes)
2{
3 return ViewerBuilder2.WithUri(fileUri)
4 .UsingCustomToolbar(menuRes)// Specify a custom toolbar
5 .UsingNavIcon(navIcon) // Specify a custom navigation component
6 .Build(context);
7}
To change the icon color and overflow icon color, in styles.xml:
If you would like to interact with the host fragment you can override the methods that you are interested in through events. For example, you may want to override ToolbarOptionsItemSelected 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 NavButtonPressed.
Here's an example that replaces the default navigation icon and uses a custom toolbar: