Documentation Index
Fetch the complete documentation index at: https://mahmoud-b28887f9.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
KPdfLoadState is the observable load lifecycle for a single KPDF viewer instance. Collect it from KPdfViewerState.loadState (a StateFlow) to drive loading indicators, show page counts, surface error messages, and gate actions that require a fully decoded document. The state machine progresses linearly from Idle → Loading → Ready on success, or Idle → Loading → Error on failure. Transitioning the viewer to a new source resets the state back to Idle.
Variants
No document is loaded and no load is in progress. This is the initial state of every viewer instance before
open() is called, and the state the viewer returns to after close().The SDK is actively fetching (for URL sources) or decoding the PDF bytes. Long-running network requests remain in
Loading for their entire duration. Display a progress indicator while in this state.Document loading failed. Inspect
reason to determine the failure type and decide whether to surface a retry action or a specific error message.A sealed
KPdfError value describing the failure. See KPdfError variants below.KPdfError variants
KPdfError is a sealed interface with a message: String property on every variant. The following concrete types are available:
| Variant | Description |
|---|---|
FileNotFound(path: String?) | The local file could not be located at the given path. |
NetworkError(statusCode: Int?, reason: String?) | A network request failed, optionally with an HTTP status code and reason phrase. |
Unauthorized | The request was rejected with a 401-equivalent response. |
NotFound | The remote resource returned a 404-equivalent response. |
CorruptedDocument | The bytes were retrieved but could not be parsed as a valid PDF. |
Unknown(message: String) | An unexpected error occurred; message contains the detail. |
Collecting load state in Compose
CallcollectAsState() on KPdfViewerState.loadState inside your composable, then branch on each variant with a when expression.
pageCount is only available on the Ready variant. Guard any page-count logic with a smart cast or (loadState as? KPdfLoadState.Ready)?.pageCount to avoid a null or default value while the document is still loading.
Notes
KPdfViewerState.loadStateis aStateFlow<KPdfLoadState>, so it always has a current value and never suspends on the first collection.- Calling
viewerState.open(newSource)while inReadyorErrorresetsloadStatetoIdlebefore beginning the next load cycle. - If you only need
pageCountfor toolbar display,KPdfViewerToolbarreads it internally — you do not need to observeloadStateyourself in that case.