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
-
In your top-level
build.gradle
file, add the PSPDFKit Maven repository:allprojects { repositories { maven { url 'https://customers.pspdfkit.com/maven/' } } }
-
In your app-level
build.gradle
file, add the PSPDFKit dependency:dependencies { implementation 'com.pspdfkit:pspdfkit:6.6.0' }
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:
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 } }
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, copy the <meta-data>
below this paragraph to your app’s AndroidManifest.xml
. If you already have a license, it will be prefilled in the code example below.
<application> <meta-data android:name="pspdfkit_license_key" android:value="YOUR_LICENSE_KEY_GOES_HERE" /> </application>
💡 Tip: For additional information on how to initialize PSPDFKit, please refer to our Initializing PSPDFKit guide.
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
:
-
Copy a PDF document into the assets directory of your Android project, for example to
src/main/assets/my-document.pdf
. -
Add
PdfActivity
to your app’sAndroidManifest.xml
:<application> <activity android:name="com.pspdfkit.ui.PdfActivity" android:windowSoftInputMode="adjustNothing" /> </application>
-
You can now start
PdfActivity
with the document from your assets:val uri = Uri.parse("file:///android_asset/my-document.pdf") val config = PdfActivityConfiguration.Builder(context).build() PdfActivity.showDocument(this, uri, config)
final Uri uri = Uri.parse("file:///android_asset/my-document.pdf"); final PdfActivityConfiguration config = new PdfActivityConfiguration.Builder(context).build(); PdfActivity.showDocument(this, uri, config);
-
PdfActivity
will now present the document from your assets.
Next Steps
-
Learn how to configure
PdfActivity
to match your app’s look and feel. -
See how to add
PdfFragment
to your own activity for custom PDF integrations. -
Learn how to load PDF documents from custom data sources using data providers.