setCustomPdfSource

fun setCustomPdfSource(source: DocumentSource? = null)

Swaps the displayed document for source, or reloads the current document when source is null — without recreating the composable, the fragment, or its listeners.

When it is safe to call: any time after the DocumentView has composed and attached. Before that (or with no document loaded for a null refresh) the call is a silent no-op — no exception, failures are caught and logged.

The swap is asynchronous. Calling this triggers a fragment-level document reload and returns immediately — there is no return value or completion callback on the method itself. Completion is observed through the document listener wired into the DocumentView's DocumentManager: DefaultListeners.documentListeners's onDocumentLoaded fires again for the new document once loading completes, the same way it does for the initial document.

Preserved: the underlying fragment, the PdfActivityConfiguration, and every listener registered through the DocumentManager.

Reset: the zoom resets to 1.0 on every reload. The current page index carries over into the new document as-is; with restoreLastViewedPage enabled on the configuration (the default), the incoming document's own last-viewed page can then take over once loading completes. A caller that wants full continuity on a same-document refresh captures getViewState before the call and applies setViewState from onDocumentLoaded.

Guard the page index before replacing: because the index carries over unguarded, swapping to a document with fewer pages than the current index can crash. Set a valid page first — documentState.documentConnection.setPageIndex(0) — before passing a different, potentially shorter document.

See the catalog's CustomPdfSourceExample for both patterns (replace and refresh), and ComposePdfViewerExample's viewer screen for the view-state-restoring refresh.

Parameters

source

The new document source, or null to reload the current source.