Some test text!

Open a documentkeyboard_arrow_down

Open a document

You have a few options to open a document such as with an activity, fragment, or view. A diagram of the overall view hierarchy can be found here: View hierarchy.

Show a document in an Activity

DocumentActivity requires the full version of the PDFTron library. See PDFTron full or standard?

PDFTron's Android SDK ships with DocumentActivity, an all-in-one document reader and PDF editor. In addition to PDF files, it also supports viewing other file formats such as .docx, .doc, .pptx, .xlsx, .md, .cbz and various image formats. In this activity you can also read, annotate, sign, fill in PDF forms and more.

DocumentActivity extends Android's AppCompatActivity and follows Material design guidelines.



For trial purposes PDFTron is available without the need for a license key, however a valid license key is required to use PDFTron in a production app. If you do not have a valid license key, please contact sales for a commercial license key.

Your license key is confidential. Please make sure that it is not publicly available (e.g. in your public GitHub).

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:

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 multidex support, enable largeHeap, and enable usesCleartextTraffic -->
            <!-- Add license key in meta-data tag here. This should be inside the application tag. -->
            <!-- Document viewer activity declaration-->
            <activity android:name="com.pdftron.pdf.controls.DocumentActivity"

linkStep 2: Launch the viewer

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

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);

// from assets
final Uri assetUri = Uri.parse("file:///android_asset/my_file.pdf");
DocumentActivity.openDocument(context, assetUri);
// or if using config
DocumentActivity.openDocument(context, assetUri, config);
// or if using config and opening password protected file
DocumentActivity.openDocument(context, assetUri, password, config);

linkStep 3: (Optional) Customize the viewer

  • If you would like to customize the appearance of the viewer activity, define CustomAppTheme in res/values/styles.xml:

    <style name="CustomAppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
        <item name="colorPrimary">@color/app_color_primary_day</item>
        <item name="colorPrimaryDark">@color/app_color_primary_dark_day</item>
        <item name="colorAccent">@color/app_color_accent</item>
        <!-- Action bar -->
        <item name="actionModeBackground">?attr/colorPrimary</item>
        <item name="windowActionModeOverlay">true</item>

    Alternatively, if you cannot use NoActionBar as a base theme:

    DocumentActivity extends AppCompatActivity and uses AppCompat Toolbar. It is important that you define a Theme.AppCompat theme for CustomAppTheme. The recommended theme is Theme.AppCompat.*.NoActionBar. Other custom themes can also be used, however be sure to disable the action bar manually:

    <style name="CustomAppTheme" parent="Theme.AppCompat.*">
        <!-- Action bar -->
        <item name="windowActionModeOverlay">true</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
  • Also, if you would like to customize the UI components in DocumentActivity, you can use ViewerConfig.Builder. For example:

    import com.pdftron.pdf.config.ViewerConfig;
    ViewerConfig.Builder builder = new ViewerConfig.Builder();
    ViewerConfig config = builder
        .toolbarTitle("Simple Reader")

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

Get the answers you need: Support


Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

PDFTron Receives USD$71 Million Growth Investment Led By Silversmith Capital Partners

Learn more