Some test text!

View a documentkeyboard_arrow_down

Quick start - view a document in Android


  • Minimum API: 16 (using AndroidX)
  • Compile API: 29
  • Recommended target API: 29
  • The latest version of Android Studio.
  • If your app is using AndroidX you will also need to add android.useAndroidX=true and android.useAndroidX=true in your file. You can learn more about this here .
No trial license key required.
The trial of PDFTron SDK works without a license key. A commercial license key is required for use in a production environment. Please fill out our licensing form if you do not have a valid license key.
Keep your commercial license key confidential.
License keys are uniquely generated. Please make sure that it is not publicly available (e.g. in your public GitHub).

In this quick start tutorial you will create a simple Android app that will open a PDF document stored in your Android project by using DocumentActivity. The sample code for this tutorial is available at our GitHub repository.

  1. On the Android welcome screen, click Start a new Android Studio project:
android_studio_welcome image
  1. Create a new Android Studio project with an Empty Activity and set the minimum SDK to API 16. You can learn more about PDFTron's system requirements here .
  2. For simplicity, we'll integrate the PDFTron SDK into our project using Gradle. You can learn more about how Gradle is used in Android Studio at the Gradle guides.

    Find your file in the root folder of your project and add your license key to this file:

No trial license key required.
The trial of PDFTron SDK works without a license key. A commercial license key is required for use in a production environment. Please fill out our licensing form if you do not have a valid license key.
Keep your commercial license key confidential.
License keys are uniquely generated. Please make sure that it is not publicly available (e.g. in your public GitHub).
  1. Also in your file, add the following AndroidX flags if they do not already exist:

    # AndroidX package structure to make it clearer which packages are bundled with the
    # Android operating system, and which are packaged with your app's APK
    # Automatically convert third-party libraries to use AndroidX
  2. Now find your project's root-level build.gradle file:


    and add the PDFTron Maven repository to the repositories tag:

    allprojects {
        repositories {
            maven {
                url ""
    Please make sure the above is added to the repositories block in the allprojects, not in buildscript.
  3. Then in your app module's build.gradle file (usually app/build.gradle) add the following:

    android {
        defaultConfig {
            multiDexEnabled true
            vectorDrawables.useSupportLibrary = true
            manifestPlaceholders = [pdftronLicenseKey:PDFTRON_LICENSE_KEY]
    dependencies {
        implementation "com.pdftron:pdftron:9.0.1"
        implementation "com.pdftron:tools:9.0.1"
        implementation 'androidx.multidex:multidex:2.0.1'

    You should also sync your project when you make changes in your Gradle files.

    If you encountered any issue with gradle sync, check out the Troubleshooting guide.
  4. In order to support all the features in DocumentActivity, we need to include the Android permissions listed in the table below. However if you would like to disable certain features and customize your document viewer, you should leave out unnecessary permissions. You can learn more about permissions here .

    FeatureRelevant permission
    Accessing documents in local storage, including:
    • Reading documents in local storage
    • Writing to PDF files (including annotation creation) in local storage
    • Creating PDF files in local storage
    • Opening a PDF from a URL
    • HTML to PDF conversion
    • Realtime collaboration
    • Creating sound annotations

    In this sample we'll add all the permissions to AndroidManifest.xml so we can support all the features in the viewer. In this file, we'll also need to add a reference to our PDFTron license key. The resulting 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 and enable largeHeap.
             Also enable usesCleartextTraffic in application attributes if you are 
             working with HTTP files. If you are only working with HTTPS files, this is not required.-->
            <!-- 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"
  5. If you would like to customize the appearance of the viewer activity, define PDFTronAppTheme (referenced by DocumentActivity in AndroidManifest.xml) in res/values/styles.xml:

        <!-- Custom theme that will be used by the document reader -->
        <style name="PDFTronAppTheme" parent="PDFTronAppThemeBase">
            <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>

    You can learn more about this in the customize the viewer's theme guide .

  6. Now add a PDF file to the res/raw folder of your project (you can use our sample here) and call it sample.pdf, we are going to reference this file in the next step.
android_studio_welcome image
  1. In onCreate of your launcher activity, call DocumentActivity.openDocument(Context, int) to open this PDF file with the document reader:

    // ...
    protected void onCreate(Bundle savedInstanceState) {
        // Open our sample document in the 'res/raw' resource folder
        DocumentActivity.openDocument(this, R.raw.sample);

    This launches DocumentActivity with our sample PDF document with default viewer configurations, and you should see the following: DocumentActivity image

    You can also view your document in DocumentActivity by specifiying a local file path, an HTTP/HTTPS url, or a Content Uri:

    // Open a local document given a path
    private void openLocalDocument(Context context, String localFilePath) {
        final Uri localFile = Uri.fromFile(new File(localFilePath));
        DocumentActivity.openDocument(context, localFile);
    // Open a document given a Content Uri
    private void openContentUriDocument(Context context, Uri contentUri) {
        DocumentActivity.openDocument(context, contentUri);
    // Open a document from HTTP/HTTPs
    private void openHttpDocument(Context context, String url) {
        final Uri fileLink = Uri.parse(url);
        DocumentActivity.openDocument(context, fileLink);
    // Open a document stored in the 'src/main/res/raw' folder
    private void openRawResourceDocument(Context context, @IdRes int fileResId) {
        DocumentActivity.openDocument(context, fileResId);

    Please note that any changes made to files opened from res/raw will not be saved on the disk.

    The source code for this tutorial can be found on our GitHub repository.

Next steps

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.