---
title: "PDF display options on Android with PdfFragment | Nutrient"
canonical_url: "https://www.nutrient.io/guides/android/basics/using-fragment/"
md_url: "https://www.nutrient.io/guides/android/basics/using-fragment.md"
last_updated: "2026-05-15T19:10:04.924Z"
description: "Nutrient provides two kinds of fragments for displaying PDF documents:."
---

# PDF display options on Android with PdfFragment

Nutrient provides two kinds of fragments for displaying PDF documents:

- [`PdfFragment`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-fragment/index.html) is meant for users who want to fully customize and control the PDF display. It shows only the document and does not feature additional views like the thumbnail bar, search, outline, etc.

- [`PdfUiFragment`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-ui-fragment/index.html) works like the [ready-to-use PDF viewer activities](https://www.nutrient.io/guides/android/basics/using-activity.md) and provides all the features the [`PdfActivity`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-activity/index.html) provides. You can use this if using a [`PdfActivity`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-activity/index.html) is not possible because you have to use a specific activity subclass already. However, if at all possible, we still recommend using [`PdfActivity`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-activity/index.html) over using [`PdfUiFragment`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-ui-fragment/index.html).

## Setting up the manifest

No matter which kind of fragment you end up using, the first step before adding either in your activity is to ensure that your application is prepared for displaying and editing PDFs.

Make sure you have the `android:largeHeap="true"` property in your `<application>` tag in `AndroidManifest.xml`. Rendering PDF files can be memory intensive, and this property will ensure your app has enough heap allocated to avoid hitting out-of-memory errors:

```xml

<application android:largeHeap="true">...
</application>

```

## Configuring the fragment

Just like the [`PdfActivity`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-activity/index.html), both [`PdfFragment`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-fragment/index.html) and [`PdfUiFragment`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-ui-fragment/index.html) allow passing in a configuration object that defines various options.

### PdfFragment

For the [`PdfFragment`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-fragment/index.html), create the [`PdfConfiguration`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.configuration/-pdf-configuration/-builder/index.html) and pass the desired settings, e.g. scroll orientation, scroll mode, and rendering settings:

### KOTLIN

```kotlin

val configuration = PdfConfiguration.Builder().scrollDirection(PageScrollDirection.HORIZONTAL).build()

```

### JAVA

```java

final PdfConfiguration configuration = new PdfConfiguration.Builder().scrollDirection(PageScrollDirection.HORIZONTAL).build();

```

### PdfUiFragment

For the [`PdfUiFragment`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-ui-fragment/index.html) use a [`PdfActivityConfiguration`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.configuration.activity/-pdf-activity-configuration/index.html) instead of [`PdfConfiguration`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.configuration/-pdf-configuration/-builder/index.html). Otherwise, the configuration works the same.

## Adding fragment to your activity

### PdfFragment

Add [`PdfFragment`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-fragment/index.html) to your activity just like you would any other Android fragment. Create the fragment using [`PdfFragment.newInstance()`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-fragment/new-instance.html) and attach it to your activity. This is usually done within the [`onCreate()`](https://developer.android.com/reference/android/app/Activity.html#onCreate(android.os.Bundle)) method of your activity. Since fragments are retained over configuration changes, make sure you don’t recreate the fragment if it already exists:

### KOTLIN

```kotlin

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_custom_fragment)

    // First, try to restore a previously created fragment. If no fragment exists, create a new one.
    val fragment = supportFragmentManager.findFragmentById(R.id.fragmentContainer) as PdfFragment?: createFragment(documentUri, configuration)
}

private fun createFragment(documentUri: Uri, configuration: PdfConfiguration): PdfFragment {
    val fragment = PdfFragment.newInstance(documentUri, configuration)
    supportFragmentManager.beginTransaction().replace(R.id.fragmentContainer, fragment).commit()
    return fragment
}

```

### JAVA

```java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_custom_fragment);

    // First, try to restore a previously created fragment.
    PdfFragment fragment = (PdfFragment) getSupportFragmentManager().findFragmentById(R.id.fragmentContainer);

    // If no fragment exists, create a new one.
    if (fragment == null) {
        fragment = PdfFragment.newInstance(documentUri, configuration);
        getSupportFragmentManager().beginTransaction().replace(R.id.fragmentContainer, fragment).commit();
    }
}

```

### PdfUiFragment

### KOTLIN

```kotlin

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_custom_fragment)

    // First, try to restore a previously created fragment. If no fragment exists, create a new one.
    val fragment = supportFragmentManager.findFragmentById(R.id.fragmentContainer) as PdfUiFragment?: createFragment(documentUri, configuration)
}

private fun createFragment(documentUri: Uri, configuration: PdfActivityConfiguration): PdfFragment {
    val fragment = PdfUiFragmentBuilder.fromUri(this, documentUri).configuration(configuration).build()
    supportFragmentManager.beginTransaction().replace(R.id.fragmentContainer, fragment).commit()
    return fragment
}

```

### JAVA

```java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_custom_fragment);

    // First, try to restore a previously created fragment.
    PdfUiFragment fragment = (PdfUiFragment) getSupportFragmentManager().findFragmentById(R.id.fragmentContainer);

    // If no fragment exists, create a new one.
    if (fragment == null) {
        fragment = PdfUiFragmentBuilder.fromUri(this, documentUri).configuration(configuration).build();
        getSupportFragmentManager().beginTransaction().replace(R.id.fragmentContainer, fragment).commit();
    }
}

```

Make sure your Activity doesn’t have an action bar (e.g. by using a `.NoActionBar` theme), because [`PdfUiFragment`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-ui-fragment/index.html) comes with its own.

Since [`PdfFragment`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-fragment/index.html) and [`PdfUiFragment`](https://www.nutrient.io/api/android/nutrient/com.pspdfkit.ui/-pdf-ui-fragment/index.html) extend [`androidx.fragment.app.Fragment`](https://developer.android.com/reference/androidx/fragment/app/Fragment.html), your activity needs to subclass [`FragmentActivity`](https://developer.android.com/reference/androidx/fragment/app/FragmentActivity.html), which is part of the [AndroidX](https://developer.android.com/jetpack/androidx) libraries. Once this is done, you can then access the fragment manager using `getSupportFragmentManager()`.

## Building an activity around PdfFragment

Nutrient ships with all the views used in `PdfActivity` as standalone widgets. If you wish to use these existing Nutrient widgets in your custom activities, follow the [building an activity around `PdfFragment`](https://www.nutrient.io/guides/android/customizing-the-interface/building-an-activity-around-the-pdffragment/) guide.
---

## Related pages

- [Load PDF documents on Android with PdfDocument class](/guides/android/basics/using-pdfdocument.md)
- [Display PDFs on Android with PdfActivity](/guides/android/basics/using-activity.md)

