Add PDF functionality in Android
This guide helps you integrate Nutrient Android SDK into either a new or existing Android project, using Gradle or manual AAR integration. It also shows how to display a PDF using either PdfActivity
or Jetpack Compose’s DocumentView
.
Prefer to jump straight to code? View the example repo on GitHub.
Explore SDK capabilities through our interactive demos.
Creating or opening your project
If you already have an Android project, open it in Android Studio. Otherwise, create a new one by following the steps below.
Open Android Studio, select File > New > New Project.
Choose the Empty Views Activity or Empty Activity (Jetpack Compose) template.
Set your app name (for example, Nutrient Demo), desired save location, language (for example, Kotlin), and minimum SDK (21+ recommended).
Click Finish to create the project.
Adding Nutrient to your project
You can add the SDK using Gradle (recommended) or manually using an AAR file.
In the
settings.gradle.kts
file at the root of your project, add the Nutrient Maven repository:dependencyResolutionManagement {repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)repositories {google()mavenCentral()maven {url = uri("https://my.nutrient.io/maven")}}}In your
app/build.gradle.kts
file, add the Nutrient dependency:dependencies {implementation("io.nutrient:nutrient:${LATEST_VERSIONS.ANDROID_SDK}")}
Copy it to your project’s
libs
directory.Add it as a file-based dependency along with the required transitive dependencies:
dependencies {implementation(files("libs/Nutrient-Android-SDK-AAR-${LATEST_VERSIONS.ANDROID_SDK}.aar"))// You must include all transitive dependencies of Nutrient.implementation("androidx.appcompat:appcompat:1.7.0")implementation("androidx.cardview:cardview:1.0.0")implementation("androidx.compose.material3:material3:1.3.1")implementation("androidx.compose.runtime:runtime:1.7.8")implementation("androidx.compose.runtime:runtime-rxjava3:1.7.8")implementation("androidx.compose.ui:ui:1.7.8")implementation("androidx.constraintlayout:constraintlayout:2.2.0")implementation("androidx.exifinterface:exifinterface:1.3.7")implementation("androidx.fragment:fragment-ktx:1.8.5")implementation("androidx.fragment:fragment-compose:1.8.5")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.4.0")implementation("androidx.viewpager2:viewpager2:1.1.0")implementation("androidx.webkit:webkit:1.12.1")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:2.0.20")implementation("org.jetbrains.kotlin:kotlin-stdlib:2.0.20")implementation("org.jetbrains.kotlin:kotlin-parcelize-runtime:2.0.20")implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.8")implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.1")}flatDir
repositories have been deprecated since Android Gradle plugin (AGP) 3.5. Use file-based AAR dependencies.
Configuring your build
Ensure the following configuration in app/build.gradle.kts
:
android { compileSdk = 35
defaultConfig { applicationId = "com.example.app" minSdk = 21 targetSdk = 35 }
compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 }
kotlinOptions { jvmTarget = "17" }}
With
minSdk
set to21
, your app is available on more than 99.4 percent(opens in a new tab) of Android devices (as of June 2025).
Displaying a PDF
You can display PDFs using either PdfActivity
(classic view system) or DocumentView
(Jetpack Compose).
Copy a PDF file to
src/main/assets/my-document.pdf
.Add
PdfActivity
toAndroidManifest.xml
:<application>...<activityandroid:name="com.pspdfkit.ui.PdfActivity"android:windowSoftInputMode="adjustNothing" /></application>Launch it in your
MainActivity.kt
:class MainActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)enableEdgeToEdge()setContentView(R.layout.activity_main)ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)insets}val uri = Uri.parse("file:///android_asset/my-document.pdf")val config = PdfActivityConfiguration.Builder(this).build()PdfActivity.showDocument(this, uri, config)}}
Ensure you’re using
AppCompatActivity
and a compatible Compose theme:...<activityandroid:name=".MainActivity"...android:theme="@style/Theme.AppCompat.NoActionBar"></activity><application>Launch
DocumentView
inside your Compose user interface (UI):class MainActivity : AppCompatActivity() {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())}}}}
The assets folder is read-only. For writing capabilities, copy PDFs to a writable directory. For more information, refer to our guide on opening PDFs from URLs.
Next steps
- Customize PdfActivity to match your UI
- Use
PdfFragment
for modular PDF display - Load PDFs from custom sources
- Add collaboration with Instant
- Add OCR support
- Use
DocumentState
withDocumentView
for interaction hooks.