> ## Documentation Index
> Fetch the complete documentation index at: https://mahmoud-b28887f9.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Control PDF page navigation and zoom level in KPDF

> Use KPdfViewerState to navigate pages and adjust zoom programmatically, and configure swipe and pinch-to-zoom gestures through KPdfViewerConfig.

`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.

## Page navigation

Call `nextPage`, `previousPage`, or `goToPage` on the viewer state. Each call updates `currentPageIndex`, which `KPdfViewer` observes and reacts to automatically.

```kotlin theme={null}
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:

```kotlin theme={null}
val currentPage by viewerState.currentPageIndex.collectAsState()
```

### Swipe-to-navigate

To let users swipe between pages, enable `enableSwipe` in your `KPdfViewerConfig`:

```kotlin theme={null}
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.

```kotlin theme={null}
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:

```kotlin theme={null}
Button(onClick = { viewerState.setZoom(2.5f) }) {
    Text("Set 250%")
}
```

You can also read the live zoom value:

```kotlin theme={null}
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`:

```kotlin theme={null}
val config = remember {
    KPdfViewerConfig.builder()
        .enableZoom(true)
        .zoomRange(minZoom = 1f, maxZoom = 4f)
        .doubleTapZoom(2.5f)
        .build()
}
```

| Option          | Description                                          |
| --------------- | ---------------------------------------------------- |
| `enableZoom`    | Enables pinch-to-zoom gestures on the viewer surface |
| `zoomRange`     | Sets the minimum and maximum zoom factors            |
| `doubleTapZoom` | Zoom factor applied when the user double-taps a page |

<Tip>
  `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`.
</Tip>
