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.

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.

  1. Open Android Studio, select File > New > New Project.

  2. Choose the Empty Views Activity or Empty Activity (Jetpack Compose) template.

  3. Set your app name (for example, Nutrient Demo), desired save location, language (for example, Kotlin), and minimum SDK (21+ recommended).

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

  1. 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")
    }
    }
    }
  2. In your app/build.gradle.kts file, add the Nutrient dependency:

    dependencies {
    implementation("io.nutrient:nutrient:${LATEST_VERSIONS.ANDROID_SDK}")
    }

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 to 21, 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).

  1. Copy a PDF file to src/main/assets/my-document.pdf.

  2. Add PdfActivity to AndroidManifest.xml:

    <application>
    ...
    <activity
    android:name="com.pspdfkit.ui.PdfActivity"
    android:windowSoftInputMode="adjustNothing" />
    </application>
  3. 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)
    }
    }

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