Skip to main content

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.

KPdfViewerState exposes navigation and zoom as simple method calls, so you can wire them to any button, gesture handler, or keyboard shortcut in your UI. Gesture-based navigation and pinch-to-zoom are configured separately in KPdfViewerConfig before the viewer is created. Call nextPage, previousPage, or goToPage on the viewer state. Each call updates currentPageIndex, which KPdfViewer observes and reacts to automatically.
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
    Button(onClick = { viewerState.previousPage() }) {
        Text("Previous")
    }

    Button(onClick = { viewerState.nextPage() }) {
        Text("Next")
    }

    Button(onClick = { viewerState.goToPage(9) }) {
        Text("Jump to page 10")
    }
}
goToPage takes a 0-based index, so page 10 is index 9. You can read the current page at any time from the state flow:
val currentPage by viewerState.currentPageIndex.collectAsState()

Swipe-to-navigate

To let users swipe between pages, enable enableSwipe in your KPdfViewerConfig:
val config = remember {
    KPdfViewerConfig.builder()
        .enableSwipe(true)
        .build()
}
Set it to false if you want to restrict navigation to programmatic calls only.

Zoom controls

Call zoomIn, zoomOut, resetZoom, or setZoom to change the zoom level. Changes propagate to KPdfViewer through the currentZoom state flow.
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
    Button(onClick = { viewerState.zoomOut() }) {
        Text("Zoom out")
    }

    Button(onClick = { viewerState.zoomIn() }) {
        Text("Zoom in")
    }

    Button(onClick = { viewerState.resetZoom() }) {
        Text("Reset")
    }
}
To jump to a specific zoom factor, call setZoom directly:
Button(onClick = { viewerState.setZoom(2.5f) }) {
    Text("Set 250%")
}
You can also read the live zoom value:
val zoom by viewerState.currentZoom.collectAsState()
Text("Zoom: ${(zoom * 100).toInt()}%")

Pinch-to-zoom and zoom range

Configure pinch-to-zoom and its limits in KPdfViewerConfig:
val config = remember {
    KPdfViewerConfig.builder()
        .enableZoom(true)
        .zoomRange(minZoom = 1f, maxZoom = 4f)
        .doubleTapZoom(2.5f)
        .build()
}
OptionDescription
enableZoomEnables pinch-to-zoom gestures on the viewer surface
zoomRangeSets the minimum and maximum zoom factors
doubleTapZoomZoom factor applied when the user double-taps a page
resetZoom resets the zoom to minZoom from the configured zoomRange. If you want a “fit page” behaviour, set minZoom to 1f (the default) and call resetZoom.