This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/android/customizing-the-interface/building-an-activity-around-the-pdffragment.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Building an activity around the PdfFragment

You might want to customize the user interface of your app beyond what is possible with the predefined UI of the PdfActivity. The greatest flexibility can be achieved by embedding the PdfFragment into a custom AppCompatActivity(opens in a new tab). This guide covers using the fragment in a custom environment alongside the Nutrient widgets that PdfActivity also uses.

This article describes how to manually build a custom activity that uses the PdfFragment and other framework widgets. The other, simpler solutions are to either extend the existing PdfActivity or load a document into the default PdfActivity. You can also use the PdfUiFragment to display the document with the same UI the PdfActivity uses. To see how, refer to the guide on how to use a fragment.

Embedding the fragment

Our PdfFragment guide shows the basics of setting up the PdfFragment by providing a license and configuration. A runnable code example can be found inside our Catalog app: The FragmentExample showcases how to use the PdfFragment in a custom AppCompatActivity(opens in a new tab).

The PdfActivity offers two kinds of search. The inline search bar is part of its main toolbar and isn’t available as a standalone view. For a custom activity, use one of these:

  • PdfSearchViewModular is an expandable panel that sits above the document area. It shows a full scrollable list of all results, including preview snippets. Tapping a result closes the search view and navigates to the page containing the result.
  • The text search API, TextSearch, for a search UI of your own. CustomSearchUiExample in the Catalog app builds one.

Providing toolbars

The SDK’s main toolbar and contextual toolbars are Jetpack Compose components. A custom activity can mount them around the fragment, in a Compose layout or as a ComposeView in a View layout. Have a look at the using toolbars within fragment guide for the recipe.

Form editing UI

PdfActivity includes the form editing UI out of the box. To integrate the form editing UI into your custom activity, refer to the using the form editing UI within fragment guide.