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.6.3 as the IDE and Android Gradle plugin 3.6.3 or higher for development.

Step 1: Adding PSPDFKit to Your Project

  1. In your top-level build.gradle file, add the PSPDFKit Maven repository:

    build.gradle
    1
    2
    3
    4
    5
    6
    7
    
    allprojects {
        repositories {
            maven {
                url 'https://customers.pspdfkit.com/maven/'
            }
        }
    }
    
  2. In your app-level build.gradle file, add the PSPDFKit dependency:

    app/build.gradle
    1
    2
    3
    
    dependencies {
        implementation 'com.pspdfkit:pspdfkit:6.5.1'
    }
    

Step 2: Configuring Your Build

PSPDFKit is supported on Android devices running API level 19 and newer, targeting the latest stable Android version 10 (API 29). Furthermore, PSPDFKit requires apps to enable Java 8 language features in order to build.

Inside your app-level build.gradle file, make sure to have the following configuration:

Copy
app/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
    }
}
With minSdkVersion set to 19 your app is available on more than 98.1 percent of devices on the Google Play Store (last update: June 2020).

Step 3: Getting the License Key

PSPDFKit is a commercial product and requires a license key during framework initialization. Make sure you have either a demo license or a full license before continuing.

  • Requesting a demo license key takes only a few minutes. To get one, visit https://pspdfkit.com/try and follow the steps there.
  • If you own a full license of PSPDFKit for Android, log in to the PSPDFKit Customer Portal and retrieve your license key from there.

Step 4: Initializing PSPDFKit

PSPDFKit for Android automatically initializes itself during your app’s startup. To make sure it can find your license key, you have to set it inside your app’s AndroidManifest.xml:

Copy
app/src/main/AndroidManifest.xml
1
2
3
4
5
<application>
    <meta-data
        android:name="pspdfkit_license_key"
        android:value="YOUR_LICENSE_KEY_GOES_HERE" />
</application>

Step 5: Opening a PDF Document (Optional)

To verify that PSPDFKit was successfully integrated into your app, try opening a PDF file using the ready-to-use PdfActivity:

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

  2. Add PdfActivity to your app’s AndroidManifest.xml:

    Copy
    app/src/main/AndroidManifest.xml
    1
    2
    3
    4
    5
    
    <application>
        <activity
            android:name="com.pspdfkit.ui.PdfActivity"
            android:windowSoftInputMode="adjustNothing" />
    </application>
    
  3. You can now start PdfActivity with the document from your assets:

    Copy
    1
    2
    3
    
    val uri = Uri.parse("file:///android_asset/my-document.pdf")
    val config = PdfActivityConfiguration.Builder(context).build()
    PdfActivity.showDocument(this, uri, config)
    
    Copy
    1
    2
    3
    
    final Uri uri = Uri.parse("file:///android_asset/my-document.pdf");
    final PdfActivityConfiguration config = new PdfActivityConfiguration.Builder(context).build();
    PdfActivity.showDocument(this, uri, config);
    
  4. PdfActivity will now present the document from your assets.

Next Steps