Some test text!

platform
search

View a document

Contents

Prerequisites
Step 1: Update AndroidManifest.xml
Step 2: Launch the viewer
Next steps
DocumentActivity requires the full version of the PDFTron library. See PDFTron full or standard?

linkPrerequisites

  • Integrated PDFTron into your project and added the com.pdftron:tools package into your project.
  • A valid evaluation or commercial license key. If you do not have a license key, please contact sales for a commercial license key or click here to get an evaluation key.
  • Minimum API: 16 (using Android Support Libraries)
  • Recommended target API: 28

linkStep 1: Update AndroidManifest.xml

  1. In order to support all the features in DocumentActivity, 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.
  1. Enable largeHeap, usesClearTextTraffic, and set android:name in the <application> tag to MultiDexApplication:

    <application
        ...
        android:name="android.support.multidex.MultiDexApplication"
        android:largeHeap="true"
        android:usesCleartextTraffic="true">
        ...
    </application>
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.
  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. Also, declare DocumentActivity in the same file. The final AndroidManifest.xml file should look something like this:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest ...>
        <!-- Required permissions are added here -->
        <uses-permission android:name="android.permission.INTERNET"/>
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.RECORD_AUDIO" />
    
        <!-- Add license key in meta-data tag here -->
        <meta-data
            android:name="pdftron_license_key"
            android:value="${pdftronLicenseKey}"/>
    
        <!-- Add multidex support, enable largeHeap, and enable usesCleartextTraffic -->
        <application 
            ...
            android:name="android.support.multidex.MultiDexApplication"
            android:largeHeap="true"
            android:usesCleartextTraffic="true">    
                
            <!-- Document viewer activity declaration-->
            <activity android:name="com.pdftron.pdf.controls.DocumentActivity"
                android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize"
                android:windowSoftInputMode="adjustPan"
                android:theme="@style/CustomAppTheme"/>
            ...
        </application>
    </manifest>

linkStep 2: Launch the viewer

Launch DocumentActivity by specifiying a local file path, an HTTP/HTTPS url, or a Content Uri:

import android.net.Uri;
import java.io.File;
import com.pdftron.pdf.controls.DocumentActivity;

// from internal storage
final Uri localFile = Uri.fromFile(new File("myLocalFilePath"));
DocumentActivity.openDocument(context, localFile);
// or if using config
DocumentActivity.openDocument(context, localFile, config);
// or if using config and opening password protected file
DocumentActivity.openDocument(context, localFile, password, config);

// from content uri
final Uri contentUri = Uri.parse("myContentUri");
DocumentActivity.openDocument(context, contentUri);
// or if using config
DocumentActivity.openDocument(context, contentUri, config);
// or if using config and opening password protected file
DocumentActivity.openDocument(context, contentUri, password, config);

// from http/https
final Uri fileLink = Uri.parse("myFileLink");
DocumentActivity.openDocument(context, fileLink);
// or if using config
DocumentActivity.openDocument(context, fileLink, config);
// or if using config and opening password protected file
DocumentActivity.openDocument(context, fileLink, password, config);

// from res
DocumentActivity.openDocument(context, R.raw.my_file_res_id);
// or if using config
DocumentActivity.openDocument(context, R.raw.my_file_res_id, config);
// or if using config and opening password protected file
DocumentActivity.openDocument(context, R.raw.my_file_res_id, password, config);

linkNext steps

Get the anwsers you need: Support

Contents

Prerequisites
Step 1: Update AndroidManifest.xml
Step 2: Launch the viewer
Next steps