Opening multiple PDFs in our Android viewer
Nutrient Android SDK supports loading multiple documents into a single PdfActivity. This guide will outline how to launch the PdfActivity, as well as how to control which documents are displayed.
Launching PdfActivity
Depending on how many documents you want to display in the PdfActivity, you can launch it in different ways.
Displaying one document
If you’re just displaying a single document, the PdfActivity itself has a convenient method to do this:
// Shows the document found at the given URI.PdfActivity.showDocument(context, uri, configuration)// Shows the document found at the given URI.PdfActivity.showDocument(context, uri, configuration);Displaying multiple documents
If you need to display two or more documents in a PdfActivity, you’ll have to use the PdfActivityIntentBuilder:
// `PdfActivity` uses a document descriptor to identify each document that should be loaded.// These will be displayed as tabs if the tabs UI is enabled in the configuration.val intent = PdfActivityIntentBuilder.fromDocumentDescriptor( context, // Shows the document found at the given URI. DocumentDescriptor.fromUri(documentUri), // You can also serve the document via `DataProvider`. DocumentDescriptor.fromDataProvider(dataProvider), // Or you can show an image document. DocumentDescriptor.imageDocumentFromUri(documentUri)) .configuration(configuration) // Show the second document (zero-based index) initially. .visibleDocument(1) .build()context.startActivity(intent)// `PdfActivity` uses a document descriptor to identify each document that should be loaded.// These will be displayed as tabs if the tabs UI is enabled in the configuration.Intent intent = PdfActivityIntentBuilder.fromDocumentDescriptor( context, // Shows the document found at the given URI. DocumentDescriptor.fromUri(documentUri), // You can also serve the document via `DataProvider`. DocumentDescriptor.fromDataProvider(dataProvider), // Or you can show an image document. DocumentDescriptor.imageDocumentFromUri(documentUri)) .configuration(configuration) // Show the second document (zero-based index) initially. .visibleDocument(1) .build();context.startActivity(intent);Displaying PdfActivity without documents
Finally, you can also start the PdfActivity without any document at all using emptyActivity():
// Shows the empty activity.val intent = PdfActivityIntentBuilder.emptyActivity(context) .configuration(configuration) .build()context.startActivity(intent)// Shows the empty activity.Intent intent = PdfActivityIntentBuilder.emptyActivity(context) .configuration(configuration) .build();context.startActivity(intent);Managing displayed documents
Once you start the PdfActivity, you can manage the displayed documents by using the DocumentCoordinator. To obtain an instance, use PdfActivity#getDocumentCoordinator(). To see an example of how this can be used, check out DocumentTabsExample in our Catalog app:
// Add a new document.documentCoordinator.addDocument(descriptor)
// Display the newly added document.documentCoordinator.setVisibleDocument(descriptor)
// Remove some other document.documentCoordinator.removeDocument(otherDescriptor)// Add a new document.getDocumentCoordinator().addDocument(descriptor);
// Display the newly added document.getDocumentCoordinator().setVisibleDocument(descriptor);
// Remove some other document.getDocumentCoordinator.removeDocument(otherDescriptor);UI for handling multiple documents
By default, Nutrient provides a tabbed user interface that enables the user to switch between all the currently opened documents.

The tab bar is the PdfTabBar view in the PdfActivity layout, rendered in Jetpack Compose. Its public API is unchanged:
PdfActivityConfiguration.Builder.setTabBarHidingMode()controls when it shows:AUTOMATIC(the default, only with more than one document),AUTOMATIC_HIDE_SINGLE,SHOW, orHIDE.setCloseMode()on the bar decides which tabs get a close button:CLOSE_ONLY_SELECTED_TAB,CLOSE_ENABLED, orCLOSE_DISABLED.- The bar is a
LinearLayout, so you can add your own view — for example, an “add tab” button, withpspdfKitViews.tabBar?.addView(button, 0). The tabs take the remaining width.DocumentTabsExamplein the Catalog app does this. - Colors and dimensions come from the
pspdf__tabBarStyletheme attribute; see appearance styling.
The bar’s OnTabClickedListener and OnTabsChangedListener collections report the user’s interaction. The bar contains no RecyclerView to reach into, because the tabs are composed.
In a Jetpack Compose app that renders its own chrome around DocumentView, use the NutrientTabBar composable instead, bound to documentState.documentCoordinator. Hide the SDK’s bar with TabBarHidingMode.HIDE. DocumentTabsComposeExample in the Catalog app shows it under a floating main toolbar.
You can also build an entirely custom UI to switch between documents using the DocumentCoordinator as shown in DocumentSwitcherExample found in the Catalog app.