KPDF renders PDF documents through a small set of composables that share a single state holder. To display a PDF you choose a source, build a viewer configuration, create the state withDocumentation 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, and drop KPdfViewer into your layout. The steps below walk through each piece in order.
Choose a KPdfSource
KPdfSource describes where the PDF comes from. Pick the variant that matches your data.Create a KPdfViewerConfig with the builder
KPdfViewerConfig controls runtime behavior — zoom limits, gesture toggles, and cache sizes. Build it once inside a remember block so the reference stays stable.| Builder option | Description |
|---|---|
enableZoom | Allow pinch-to-zoom gestures |
enableSwipe | Allow swipe-to-navigate gestures |
zoomRange | Minimum and maximum zoom factors |
doubleTapZoom | Zoom factor applied on a double tap |
ramCacheSize | Number of pages to keep in RAM |
diskCacheSize | Number of pages to keep on disk |
preloadPageCount | Pages to render ahead of the current page |
Call rememberPdfViewerState
rememberPdfViewerState creates a KPdfViewerState, opens the document, and binds platform save/open effects for you. Call it at the top of your composable.source and config. Passing a new config object on every recomposition recreates the state and resets all transient flows, including openDocumentState and saveState.Keep
source and config stable. If you construct KPdfViewerConfig inline — outside a remember block — Compose recreates it on every recomposition. This causes rememberPdfViewerState to produce a new state instance, which resets openDocumentState, saveState, and other transient flows back to their initial values.