Skip to main content
KPDF exposes every stage of a document’s lifecycle — loading, rendering, saving, and picking from device — as observable StateFlow properties on KPdfViewerState. Collect these flows in your composables and respond to each state with the appropriate UI. This page covers KPdfLoadState in depth and introduces the patterns for KPdfSaveState, KPdfOpenDocumentState, and KPdfExternalOpenState.

KPdfLoadState

KPdfLoadState tracks the primary document load pipeline from the moment you call open() until the document is ready to display or an error occurs.

States

Collecting load state

Reading document metadata

Once the state is Ready, access pageCount and title from the state object:

KPdfSaveState

KPdfSaveState tracks the full lifecycle of a save or export operation initiated by requestSave() or savePdf(). The platform integration layer included with rememberPdfViewerState handles the file-picker handoff automatically, so you normally only need to observe this flow to update your UI.
Trigger the save flow from a button:

KPdfOpenDocumentState

KPdfOpenDocumentState tracks the platform file picker flow initiated by requestOpenFromDevice(). When the user selects a file, the state moves to Success and exposes the selected KPdfSource. Call viewerState.open(source) to load it.
If openDocumentState never leaves Idle after you call requestOpenFromDevice(), check that your KPdfViewerConfig and KPdfSource are stable references wrapped in remember. Recreating them on every recomposition also recreates viewerState, which resets all in-flight flows.

KPdfExternalOpenState

KPdfExternalOpenState tracks the lifecycle of handing the current PDF to an external application via openInExternalApp(). The states mirror KPdfSaveState in structure.