This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/android/knowledge-base/invoke-search-programmatically.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. How to invoke the search UI in the PdfActivity programmatically

PdfActivity offers two kinds of search, chosen with PdfActivityConfiguration.Builder.setSearchType(). How you open each from code differs.

The inline search bar lives inside the main toolbar. Open it by dispatching the search item’s action to the ToolbarCoordinator, exactly as a tap would. Then drive the search through the coordinator’s search session:

val coordinator = nutrientToolbarCoordinator()
// Open the inline search bar.
coordinator.dispatch(ToolbarAction.ItemClicked(PdfActivity.MENU_OPTION_SEARCH))
// Start searching once the session exists, and observe its results.
lifecycleScope.launch {
coordinator.searchSession.filterNotNull().first().let { session ->
session.actions.setQuery("query")
session.state.collect { state -> updateResultLabel(state.resultCount, state.selectedIndex) }
}
}

isInlineSearchActive() on PdfActivity and PdfUiFragment reports whether the bar is open; session.actions also offers selectNext(), selectPrevious(), selectIndex() and close().

The modular search view is a View in the activity layout. Show it through PSPDFKitViews, and set the query on the view once it’s visible:

pspdfKitViews.addOnVisibilityChangedListener(object : OnVisibilityChangedListener {
override fun onShow(view: View) {
(view as? PdfSearchViewModular)?.setInputFieldText("query", true)
pspdfKitViews.removeOnVisibilityChangedListener(this)
}
override fun onHide(view: View) = Unit
})
pspdfKitViews.showView(PSPDFKitViews.Type.VIEW_SEARCH)

pspdfKitViews.searchView returns the modular view, and null when inline search is configured.

Searching without the UI

To run a search and present the results yourself, use the text search API, which the search views are built on.