Creating a New Project
-
Open Android Studio and select New Project… in the File > New > New Project… menu to create a new project for your application:
-
Choose the correct template for your project. In this example, we’ll use Empty Activity:
-
When prompted, choose your app name (PSPDFKit Demo) and set the Save location, Language, and Minimum SDK (21), of your choice:
-
Click the Finish button to save the project to your default project location.
Adding PSPDFKit to Your Project
-
In the
settings.gradle
file at the root of your project, add the PSPDFKit Maven repository:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven {
url 'https://customers.pspdfkit.com/maven/'
}
}
}
dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() maven { url = uri("https://customers.pspdfkit.com/maven") } } }
-
In your
app/build.gradle
file, add the PSPDFKit dependency:
dependencies {
implementation 'com.pspdfkit:pspdfkit:8.7.2'
}
dependencies {
implementation("com.pspdfkit:pspdfkit:8.7.2")
}
Configuring Your Build
PSPDFKit is supported on Android devices running API level 21 and newer and targeting the latest stable Android version 13 (API 33). Furthermore, PSPDFKit requires apps to enable Java 8 or 11 language features to build.
Inside your app/build.gradle
file, make sure to have the following configuration:
android { compileSdk 33 defaultConfig { applicationId 'com.example.app' minSdk 21 targetSdk 33 } compileOptions { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 } }
android { compileSdk = 33 defaultConfig { applicationId = "com.example.app" minSdk = 21 targetSdk = 33 } compileOptions { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 } }
![]()
With
minSdk
set to21
, your app is available on more than 94.1 percent of devices on the Google Play Store (last update: September 2021).
Displaying a PDF
To verify that PSPDFKit was successfully integrated into your app, try opening a PDF file with 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 directory:
class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val uri = Uri.parse("file:///android_asset/my-document.pdf") val config = PdfActivityConfiguration.Builder(this).build() PdfActivity.showDocument(this, uri, config) } }
class MainActivity extends AppCompatActivity { @Override protected void onCreate(@Nullable final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); 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 directory.
![]()
Note that the
android_assets
folder is read-only and is used as a simple example. For actual usage, you might want to copy the file to a local folder first for full read and write privileges. You can read more about this in our guide on opening PDFs from URLs and in Google’s Data and file storage overview.