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.
rememberPdfViewerState is the recommended entry point for integrating KPDF into a Compose Multiplatform screen. It constructs a KPdfViewerState via KPdfFactory.create(), binds the three platform-native side-effect handlers for document open, save, and external-open flows, triggers an initial open() call for the given source, and disposes the state cleanly when the composable leaves the composition. Calling this function once is all you need before passing the returned state to KPdfViewer, KPdfViewerToolbar, and KPdfThumbnailStrip.
Signature
Parameters
Describes where the PDF comes from. Supported subtypes are:
KPdfSource.Url(url: String, headers: Map<String, String> = emptyMap())— fetches from a remote URL, with optional HTTP headers.KPdfSource.Bytes(bytes: ByteArray)— loads from in-memory bytes.KPdfSource.Base64(base64: String)— decodes a Base64-encoded PDF string.
source inside remember(source, config, sdk) { … }. Providing a new source instance that is not equal to the previous one causes the SDK to create a new viewer state and immediately call open() on the new source. Keep source stable across recompositions — see the stability warning below.Controls runtime viewer behaviour. Defaults to Like
KPdfViewerConfig.builder().build() which applies all SDK defaults. Build a custom config with the builder:source, config is a remember key. Rebuilding a new KPdfViewerConfig inline on every recomposition recreates the entire viewer state. Wrap it in remember { … } or hoist it to a stable scope.Return value
Returns aKPdfViewerState instance that is remembered for the lifetime of the composable and disposed when it leaves the composition. Pass it to connected views:
What the function does internally
- Creates the SDK facade —
KPdfFactory.create()is called once and remembered independently ofsourceandconfig. - Creates the viewer state —
sdk.viewerState(source, config)is called insideremember(source, config, sdk). A new state is produced only whensourceorconfigchanges. - Opens the document — A
LaunchedEffect(state, source)callsstate.open(source)on the IO dispatcher. - Binds platform effects — Platform-native file-picker and intent callbacks are registered automatically for save, open, and external-open flows on Android and iOS.
- Disposes on leave —
state.close()is called when the composable leaves the composition, releasing all resources including cached pages.
Usage
Manual state creation
If you need to manage the viewer lifecycle yourself — for example inside a custom ViewModel or outside of Compose — create the state directly:open(), binding any platform effects, and calling close() at the appropriate lifecycle point.
Notes
- You should use one
KPdfViewerStateper visible viewer instance. Do not share a single state between two simultaneously visibleKPdfViewercomposables. KPdfViewer,KPdfViewerToolbar, andKPdfThumbnailStripall read from the sameKPdfViewerState, so you only callrememberPdfViewerStateonce per screen.state.close()is idempotent — calling it more than once is safe and has no effect after the first call.