Integrating PSPDFKit

This section explains the process of integrating PSPDFKit into your project. PSPDFKit is designed to work best with Android Studio and the Gradle build system. We recommend Android Studio 3.5 as the IDE and Android Gradle plugin 3.5.2 or higher for development.

Getting the License Key and Maven Password

PSPDFKit is a commercial product and it uses a license key to verify your copy against the package name you have registered.

ℹ️ License Key and Maven Password

Existing customers: You need to retrieve the license key and Maven password from our Customer Portal. The steps are described below.

Demo customers: To get the license key and Maven password, request an evaluation version of PSPDFKit. If you already have, please follow the link in the demo email you received.

Getting the License Key and Maven Password

  1. Log in to the PSPDFKit Customer Portal using the credentials you received when purchasing PSPDFKit. You will see the list of all your purchased licenses.

  2. First you need to generate the license key for your applicationId. If you have already done this, you can skip this step.

    • Locate your license (e.g. PSPDFKit for Android).
    • Click the Assign license key button next to it. A dialog will open.
    • Enter the applicationId of your production app. The applicationId is a unique identifier of your app and is defined inside the app/build.gradle file:
    1
    2
    3
    4
    5
    6
    7
    
        android {
            defaultConfig {
                applicationId "com.example.yourapp"
            ...
            }
        ...
        }
    

    ℹ️ Note: If you are unsure about this step, please read our What Is a Bundle ID? guide first.

    • Click next and confirm your selected applicationId. Please double-check that the chosen identifier matches the one configured in your app, as it can no longer be changed once it’s been set.
  3. To retrieve the license key:

    • Locate your license (e.g. PSPDFKit for Android)
    • Click the License Key button next to it. A dialog will open showing you a code snippet with your license key.
  4. To retrieve the Maven password:

    • Locate your license (e.g. PSPDFKit for Android)
    • Click the Download PSPDFKit for Android button next to it.
    • Click on the Use Gradle tab to get the code snippet containing the Maven password for your build.gradle file.

Getting and Initializing the Framework

Requirements

PSPDFKit is supported on Android devices with API 19 and newer, targeting the latest stable Android version 10 (API 29). PSPDFKit uses the Android Jetpack libraries to make many of the latest Android features available on older devices. You can target devices with API 19 and newer by setting the minSdkVersion inside your app’s build.gradle. Since PSPDFKit is developed and tested on the latest Android versions, set your compileSdkVersion and targetSdkVersion to those versions as well. Finally, you also need to enable Java 8 support for your project:

Copy
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
android {
    compileSdkVersion 29
    buildToolsVersion '29.0.1'

    defaultConfig {
        applicationId 'com.example.app'
        minSdkVersion 19
        targetSdkVersion 29
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

ℹ️ Note: By targeting a minimum API of 19, your app is available on 96.4 percent of devices on the Google Play Store.

Setting the License Key

It is important that you set the license key before using any PSPDFKit classes. Add the license key in AndroidManifest.xml using the <meta-data/> tag:

Copy
1
2
3
4
5
6
7
<application..>

    <meta-data
        android:name="pspdfkit_license_key"
        android:value="YOUR_LICENSE_KEY_GOES_HERE"/>

</application>

By defining the license key in your manifest file, the framework will automatically be initialized via the content provider before any activity is displayed.

Retrieving the PSPDFKit Framework via Maven

The recommended way to integrate PSPDFKit into your app is by specifying it as a dependency inside your app’s build.gradle file:

Copy
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
repositories {
    google()
    jcenter()
    ...

    maven {
        url 'https://customers.pspdfkit.com/maven/'

        credentials {
            username 'pspdfkit'
            password 'YOUR_MAVEN_KEY_GOES_HERE'
        }
    }
}

...

dependencies {
    ...
    implementation 'com.pspdfkit:pspdfkit:6.2.0'
}

If you encounter any problems during the integration, please let us know.

Open a PDF Document

The easiest way to display a PDF document is by viewing it with PdfActivity. Here’s how you can do this.

  1. Copy a PDF document into the src/main/assets/ directory of your Android project — for example, src/main/assets/my-document.pdf.

  2. Add PdfActivity to AndroidManifest.xml right below your own MainActivity (or below any other launcher activity your app defines):

    Copy
    AndroidManifest.xml
    1
    2
    3
    4
    5
    
    <application>
        <activity
            android:name="com.pspdfkit.ui.PdfActivity"
            android:windowSoftInputMode="adjustNothing" />
    </application>
    
  3. Within MainActivity, create the required config and launch PdfActivity:

    Copy
    MainActivity.kt
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
    class MainActivity : AppCompatActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
    
            // Using the configuration builder, you can define options for the activity.
            val config = PdfActivityConfiguration.Builder(this).build()
    
            // Launch the activity, viewing the PDF document directly from the assets.
            PdfActivity.showDocument(this, Uri.parse("file:///android_asset/my-document.pdf"), config)
        }
    }
    
    Copy
    MainActivity.java
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    
    public class MainActivity extends AppCompatActivity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            // Using the configuration builder, you can define options for the activity.
            final PdfActivityConfiguration config = new PdfActivityConfiguration.Builder(this).build();
    
            // Launch the activity, viewing the PDF document directly from the assets.
            PdfActivity.showDocument(this, Uri.parse("file:///android_asset/my-document.pdf"), config);
        }
    }
    

💡 Tip: If you’d like, you can use PdfActivityConfiguration.Builder to tweak features of the launched activity.