Getting Started on Android

Creating a New Project

Open Android Studio and select File > New > New Project… to create a new project for your application:

create-new-project

  1. Choose the correct template for your project. In this example, you’ll use Empty Activity:

app-template

  1. When prompted, choose your app name (PSPDFKit Demo) and set the Save location, Language, and Minimum SDK (21), of your choice:

app-options

  1. Click Finish to save the project to your default project location.

Adding PSPDFKit to Your Project

  1. 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 = uri("https://my.pspdfkit.com/maven")
		}
	}
}
dependencyResolutionManagement {
	repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
	repositories {
		google()
		mavenCentral()
		maven {
			url "https://my.pspdfkit.com/maven/"
		}
	}
}
  1. In your app/build.gradle file, add the PSPDFKit dependency:

dependencies {
	implementation("com.pspdfkit:pspdfkit:2024.6.1")
}
dependencies {
	implementation "com.pspdfkit:pspdfkit:2024.6.1"
}

Configuring Your Build

PSPDFKit is supported on Android devices running API level 21 and newer and targeting the latest stable Android API version (API 34). Furthermore, PSPDFKit requires apps to enable, at minimum, Java 8 language features to build — though we recommend the default 17.

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

android {
    compileSdk 34

    defaultConfig {
        applicationId 'com.example.app'
        minSdk 21
        targetSdk 34
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
}
android {
    compileSdk = 34

    defaultConfig {
        applicationId = "com.example.app"
        minSdk = 21
        targetSdk = 34
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
}
Information

With minSdk set to 21, your app is available on more than 98.6 percent of devices on the Google Play Store (last update: October 2023).

Displaying a PDF

To verify that PSPDFKit was successfully integrated into your app, try opening a PDF file with 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:

<application>
    ...

    <activity
        android:name="com.pspdfkit.ui.PdfActivity"
        android:windowSoftInputMode="adjustNothing" />
</application>
  1. 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);
    }
}
  1. PdfActivity will now present the document from your assets directory.

Information

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.

Next Steps

Adding PSPDFKit to Your Project

  1. 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 = uri("https://my.pspdfkit.com/maven")
		}
	}
}
dependencyResolutionManagement {
	repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
	repositories {
		google()
		mavenCentral()
		maven {
			url "https://my.pspdfkit.com/maven/"
		}
	}
}
  1. In your app/build.gradle file, add the PSPDFKit dependency:

dependencies {
	implementation("com.pspdfkit:pspdfkit:2024.6.1")
}
dependencies {
	implementation "com.pspdfkit:pspdfkit:2024.6.1"
}

Configuring Your Build

PSPDFKit is supported on Android devices running API level 21 and newer and targeting the latest stable Android API version (API 34). Furthermore, PSPDFKit requires apps to enable, at minimum, Java 8 language features to build — though we recommend the default 17.

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

android {
    compileSdk 34

    defaultConfig {
        applicationId 'com.example.app'
        minSdk 21
        targetSdk 34
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
}
android {
    compileSdk = 34

    defaultConfig {
        applicationId = "com.example.app"
        minSdk = 21
        targetSdk = 34
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
}
Information

With minSdk set to 21, your app is available on more than 98.6 percent of devices on the Google Play Store (last update: October 2023).

Displaying a PDF

To verify that PSPDFKit was successfully integrated into your app, try opening a PDF file with 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:

<application>
    ...

    <activity
        android:name="com.pspdfkit.ui.PdfActivity"
        android:windowSoftInputMode="adjustNothing" />
</application>
  1. 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);
    }
}
  1. PdfActivity will now present the document from your assets directory.

Information

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.

Next Steps

Adding PSPDFKit to Your Project

PSPDFKit for Android can be imported manually. Below are the steps to follow if you wish to do so.

  1. Download the PSPDFKit for Android library AAR bundle from our Maven repository.

  2. Copy the PSPDFKit AAR file into your project’s libs directory, and rename it to pspdfkit-2024.6.1.aar.

  3. Include PSPDFKit as a file-based dependency in your project, and provide all the transitive dependencies required by PSPDFKit (as shown below):

dependencies {
	implementation files('libs/pspdfkit-2024.6.1.aar')

	// You must include all transitive dependencies of PSPDFKit.
	implementation 'androidx.appcompat:appcompat:1.7.0'
	implementation 'androidx.cardview:cardview:1.0.0'
	implementation 'androidx.compose.material:material:1.6.8'
	implementation 'androidx.compose.runtime:runtime-rxjava3:1.6.8'
	implementation 'androidx.compose.runtime:runtime:1.6.8'
	implementation 'androidx.compose.ui:ui:1.6.8'
	implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
	implementation 'androidx.exifinterface:exifinterface:1.3.7'
	implementation 'androidx.fragment:fragment-ktx:1.8.2'
	implementation 'androidx.gridlayout:gridlayout:1.0.0'
	implementation 'androidx.legacy:legacy-support-v4:1.0.0'
	implementation 'androidx.palette:palette:1.0.0'
	implementation 'androidx.preference:preference:1.2.1'
	implementation 'androidx.recyclerview:recyclerview:1.3.2'
	implementation 'androidx.viewpager2:viewpager2:1.1.0'
	implementation 'androidx.webkit:webkit:1.11.0'
	implementation 'com.getkeepsafe.relinker:relinker:1.4.5'
	implementation 'com.google.android.material:material:1.12.0'
	implementation 'io.reactivex.rxjava3:rxandroid:3.0.2'
	implementation 'io.reactivex.rxjava3:rxjava:3.1.6'
	implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.24'
	implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.9.24'
	implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1'
}

ℹ️ Note: Starting with the Android Gradle plugin 3.5.0, the use of flatDir repositories to include local AAR files is no longer supported. If you’ve been using this technique, you need to migrate to file-based dependencies when updating the Android Gradle plugin to 3.5.0.

The following library is included in the list of transitive dependencies:

  • ReLinker — to work around some versions of Android that have unreliable PackageManager implementations

This optional library can be omitted from the list of transitive dependencies if you don’t want to bundle it with your app. In such a case, PSPDFKit will detect the absence of this dependency and fall back to different implementations.

Displaying a PDF

To verify that PSPDFKit was successfully integrated into your app, try opening a PDF file with 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:

<application>
    ...

    <activity
        android:name="com.pspdfkit.ui.PdfActivity"
        android:windowSoftInputMode="adjustNothing" />
</application>
  1. 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);
    }
}
  1. PdfActivity will now present the document from your assets directory.

Information

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.

Next Steps

Creating a New Project

Open Android Studio and select File > New > New Project… to create a new project for your application:

create-new-project

  1. Choose the correct template for your project. In this example, you’ll use Empty Activity:

app-template

  1. When prompted, choose your app name (PSPDFKit Demo) and set the Save location, Language, and Minimum SDK (21), of your choice:

app-options

  1. Click Finish to save the project to your default project location.

Adding PSPDFKit to Your Project

  1. 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 = uri("https://my.pspdfkit.com/maven")
		}
	}
}
dependencyResolutionManagement {
	repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
	repositories {
		google()
		mavenCentral()
		maven {
			url "https://my.pspdfkit.com/maven/"
		}
	}
}
  1. In your app/build.gradle file, add the PSPDFKit dependency:

dependencies {
	implementation("com.pspdfkit:pspdfkit:2024.6.1")
}
dependencies {
	implementation "com.pspdfkit:pspdfkit:2024.6.1"
}

Configuring Your Build

PSPDFKit is supported on Android devices running API level 21 and newer and targeting the latest stable Android API version (API 34). Furthermore, PSPDFKit requires apps to enable, at minimum, Java 8 language features to build — though we recommend the default 17.

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

android {
    compileSdk 34

    defaultConfig {
        applicationId 'com.example.app'
        minSdk 21
        targetSdk 34
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
}
android {
    compileSdk = 34

    defaultConfig {
        applicationId = "com.example.app"
        minSdk = 21
        targetSdk = 34
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
}
Information

With minSdk set to 21, your app is available on more than 98.6 percent of devices on the Google Play Store (last update: October 2023).

Displaying a PDF

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

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

  2. Make sure you’re using AppCompatActivity as your parent activity.

  3. Add DocumentView in any composable scope:

class MainActivity : AppCompatActivity() {
    @OptIn(ExperimentalPSPDFKitApi::class)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Surface {
                val uri = Uri.parse("file:///android_asset/my-document.pdf")
                DocumentView(
                    documentUri = uri,
                    modifier = Modifier.fillMaxSize()
                )
            }
        }
    }
}
  1. DocumentView will now present the document from your assets directory.

Information

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 guide.

Next Steps

Cloning PSPDFKit Catalog

  1. Open the terminal app and change the current working directory. In this case, use the ~/Downloads directory:

cd ~/Downloads
  1. Clone the PSPDFKit for Android Catalog repository:

git clone https://github.com/PSPDFKit/pspdfkit-android-catalog.git
  1. Start Android Studio and open the cloned project folder from the File > Open… menu.

  2. Wait a few moments for Gradle to sync the project.

  3. Make sure you either set up an emulator with the AVD or connect an Android device.

  4. Build and run the app configuration using the Run ‘app’ button in Android Studio.

build-run-catalog-app

  1. You’ll see the PSPDFKit Catalog app on your device:

catalog-view

Next Steps