# PdfViewerState

Artifact: [androidx.pdf:pdf-compose](https://developer.android.com/jetpack/androidx/releases/pdf) [View Source](https://cs.android.com/search?q=file:androidx/pdf/compose/PdfViewerState.kt+class:androidx.pdf.compose.PdfViewerState) Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)


```
@ExperimentalPdfApi
class PdfViewerState
```

<br />

*** ** * ** ***

A state object that can be hoisted to observe and control `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewer.composable#PdfViewer(androidx.pdf.PdfDocument,androidx.pdf.compose.PdfViewerState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.pdf.ocr.OcrProvider,kotlin.Float,kotlin.Float,kotlin.Int,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp,androidx.pdf.compose.FastScrollConfiguration,androidx.compose.foundation.layout.PaddingValues,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function0,kotlin.Function1)` zoom, scroll, and content position.

## Summary

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#GESTURE_STATE_IDLE()` `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewer.composable#PdfViewer(androidx.pdf.PdfDocument,androidx.pdf.compose.PdfViewerState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.pdf.ocr.OcrProvider,kotlin.Float,kotlin.Float,kotlin.Int,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp,androidx.pdf.compose.FastScrollConfiguration,androidx.compose.foundation.layout.PaddingValues,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function0,kotlin.Function1)` is not currently being affected by an outside input, e.g. user touch |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#GESTURE_STATE_INTERACTING()` `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewer.composable#PdfViewer(androidx.pdf.PdfDocument,androidx.pdf.compose.PdfViewerState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.pdf.ocr.OcrProvider,kotlin.Float,kotlin.Float,kotlin.Int,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp,androidx.pdf.compose.FastScrollConfiguration,androidx.compose.foundation.layout.PaddingValues,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function0,kotlin.Function1)` is currently being affected by an outside input, e.g. user touch |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#GESTURE_STATE_SETTLING()` `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewer.composable#PdfViewer(androidx.pdf.PdfDocument,androidx.pdf.compose.PdfViewerState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.pdf.ocr.OcrProvider,kotlin.Float,kotlin.Float,kotlin.Int,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp,androidx.pdf.compose.FastScrollConfiguration,androidx.compose.foundation.layout.PaddingValues,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function0,kotlin.Function1)` is currently animating to a final position while not under outside control, e.g. settling on a final position following a fling gesture. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#PdfViewerState()()` |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#clearCurrentSelection()()` Clears the current selection, if one exists. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset?` | `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#getVisiblePageOffset(kotlin.Int)(visiblePageNumber: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` of the page at `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#getVisiblePageOffset(kotlin.Int)`, or null if the provided page number is not currently visible. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#pdfPointToVisibleOffset(androidx.pdf.PdfPoint)(pdfPoint: https://developer.android.com/reference/kotlin/androidx/pdf/PdfPoint)` Returns the View coordinate location of `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#pdfPointToVisibleOffset(androidx.pdf.PdfPoint)`, or `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#Unspecified()` if that PDF content has not been laid out yet. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#scrollToPage(kotlin.Int)(pageNum: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Centers the page at `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#scrollToPage(kotlin.Int)` in the viewport. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#scrollToPosition(androidx.pdf.PdfPoint)(position: https://developer.android.com/reference/kotlin/androidx/pdf/PdfPoint)` Centers the location described by `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#scrollToPosition(androidx.pdf.PdfPoint)` in the viewport |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#setHighlights(kotlin.collections.List)(highlights: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/pdf/Highlight>)` Applies a set of `https://developer.android.com/reference/kotlin/androidx/pdf/Highlight` to be drawn over this PDF. |
| `https://developer.android.com/reference/kotlin/androidx/pdf/PdfPoint?` | `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#visibleOffsetToPdfPoint(androidx.compose.ui.geometry.Offset)(offset: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset)` Returns the `https://developer.android.com/reference/kotlin/androidx/pdf/PdfPoint` corresponding to `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#visibleOffsetToPdfPoint(androidx.compose.ui.geometry.Offset)` in Compose coordinates, or null if no PDF content has been laid out at this Offset. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#zoomScroll(kotlin.Function1)(block: https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfZoomScrollScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Call this function to take control of zoom and scroll, and gain the ability to send zoom and / or scroll events via `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfZoomScrollScope`. |

| ### Public properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/pdf/selection/Selection?` | `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#currentSelection()` The currently-selected content in the PDF, or null if nothing is selected |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#firstVisiblePage()` The first page in the viewport, including partially-visible pages. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#firstVisiblePageOffset()` The `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` of the first visible page in the viewport in view coordinates. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#gestureState()` State regarding whether the user is interacting with the PDF, one of `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#GESTURE_STATE_IDLE()`, `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#GESTURE_STATE_SETTLING()`, or `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#GESTURE_STATE_INTERACTING()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#visiblePagesCount()` The number of pages visible in the viewport, including partially visible pages. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#zoom()` The zoom level of this view, as a factor of the content's natural size with when 1 pixel is equal to 1 PDF point. |

## Constants

### GESTURE_STATE_IDLE

```
const val GESTURE_STATE_IDLE: Int
```

`https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewer.composable#PdfViewer(androidx.pdf.PdfDocument,androidx.pdf.compose.PdfViewerState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.pdf.ocr.OcrProvider,kotlin.Float,kotlin.Float,kotlin.Int,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp,androidx.pdf.compose.FastScrollConfiguration,androidx.compose.foundation.layout.PaddingValues,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function0,kotlin.Function1)` is not currently being affected by an outside input, e.g. user touch

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#gestureState()` |   |

### GESTURE_STATE_INTERACTING

```
const val GESTURE_STATE_INTERACTING: Int
```

`https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewer.composable#PdfViewer(androidx.pdf.PdfDocument,androidx.pdf.compose.PdfViewerState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.pdf.ocr.OcrProvider,kotlin.Float,kotlin.Float,kotlin.Int,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp,androidx.pdf.compose.FastScrollConfiguration,androidx.compose.foundation.layout.PaddingValues,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function0,kotlin.Function1)` is currently being affected by an outside input, e.g. user touch

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#gestureState()` |   |

### GESTURE_STATE_SETTLING

```
const val GESTURE_STATE_SETTLING: Int
```

`https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewer.composable#PdfViewer(androidx.pdf.PdfDocument,androidx.pdf.compose.PdfViewerState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.pdf.ocr.OcrProvider,kotlin.Float,kotlin.Float,kotlin.Int,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp,androidx.pdf.compose.FastScrollConfiguration,androidx.compose.foundation.layout.PaddingValues,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function0,kotlin.Function1)` is currently animating to a final position while not under outside control, e.g. settling on a final position following a fling gesture.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#gestureState()` |   |

## Public constructors

### PdfViewerState

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)

```
PdfViewerState()
```

## Public functions

### clearCurrentSelection

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)

```
fun clearCurrentSelection(): Unit
```

Clears the current selection, if one exists. No-op if there is no current `https://developer.android.com/reference/kotlin/androidx/pdf/selection/Selection`

### getVisiblePageOffset

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)

```
fun getVisiblePageOffset(visiblePageNumber: @IntRange(from = 0) Int): Offset?
```

Returns the `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` of the page at `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#getVisiblePageOffset(kotlin.Int)`, or null if the provided page number is not currently visible.

### pdfPointToVisibleOffset

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)

```
fun pdfPointToVisibleOffset(pdfPoint: PdfPoint): Offset
```

Returns the View coordinate location of `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#pdfPointToVisibleOffset(androidx.pdf.PdfPoint)`, or `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#Unspecified()` if that PDF content has not been laid out yet.

Returns `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#Unspecified()` if this `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState` is not yet associated with a `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewer.composable#PdfViewer(androidx.pdf.PdfDocument,androidx.pdf.compose.PdfViewerState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.pdf.ocr.OcrProvider,kotlin.Float,kotlin.Float,kotlin.Int,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp,androidx.pdf.compose.FastScrollConfiguration,androidx.compose.foundation.layout.PaddingValues,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function0,kotlin.Function1)`, or if the `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewer.composable#PdfViewer(androidx.pdf.PdfDocument,androidx.pdf.compose.PdfViewerState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.pdf.ocr.OcrProvider,kotlin.Float,kotlin.Float,kotlin.Int,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp,androidx.pdf.compose.FastScrollConfiguration,androidx.compose.foundation.layout.PaddingValues,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function0,kotlin.Function1)` is not associated with a `https://developer.android.com/reference/kotlin/androidx/pdf/PdfDocument`

### scrollToPage

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)

```
suspend fun scrollToPage(pageNum: @IntRange(from = 0) Int): Unit
```

Centers the page at `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#scrollToPage(kotlin.Int)` in the viewport.

### scrollToPosition

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)

```
suspend fun scrollToPosition(position: PdfPoint): Unit
```

Centers the location described by `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#scrollToPosition(androidx.pdf.PdfPoint)` in the viewport

### setHighlights

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)

```
fun setHighlights(highlights: List<Highlight>): Unit
```

Applies a set of `https://developer.android.com/reference/kotlin/androidx/pdf/Highlight` to be drawn over this PDF. Each `https://developer.android.com/reference/kotlin/androidx/pdf/Highlight` may be a different color. This overrides any previous highlights, there is no merging of new and previous values. `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#setHighlights(kotlin.collections.List)` are defensively copied and the list or its contents may be modified after providing it here.

### visibleOffsetToPdfPoint

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)

```
fun visibleOffsetToPdfPoint(offset: Offset): PdfPoint?
```

Returns the `https://developer.android.com/reference/kotlin/androidx/pdf/PdfPoint` corresponding to `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#visibleOffsetToPdfPoint(androidx.compose.ui.geometry.Offset)` in Compose coordinates, or null if no PDF content has been laid out at this Offset.

Returns null if this `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState` is not yet associated with a `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewer.composable#PdfViewer(androidx.pdf.PdfDocument,androidx.pdf.compose.PdfViewerState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.pdf.ocr.OcrProvider,kotlin.Float,kotlin.Float,kotlin.Int,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp,androidx.pdf.compose.FastScrollConfiguration,androidx.compose.foundation.layout.PaddingValues,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function0,kotlin.Function1)`, or if the `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewer.composable#PdfViewer(androidx.pdf.PdfDocument,androidx.pdf.compose.PdfViewerState,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,androidx.pdf.ocr.OcrProvider,kotlin.Float,kotlin.Float,kotlin.Int,kotlin.Int,androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp,androidx.pdf.compose.FastScrollConfiguration,androidx.compose.foundation.layout.PaddingValues,kotlin.Function1,kotlin.Function1,kotlin.Function1,kotlin.Function0,kotlin.Function1)` is not associated with a `https://developer.android.com/reference/kotlin/androidx/pdf/PdfDocument`

### zoomScroll

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)

```
suspend fun zoomScroll(block: PdfZoomScrollScope.() -> Unit): Unit
```

Call this function to take control of zoom and scroll, and gain the ability to send zoom and / or scroll events via `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfZoomScrollScope`. All actions that change the logical zoom and / or scroll position must be performed within a `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#zoomScroll(kotlin.Function1)` block, even if they don't call other methods on this object in order to guarantee that mutual exclusion is enforced.

If `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#zoomScroll(kotlin.Function1)` is called from elsewhere, this will be cancelled.

## Public properties

### currentSelection

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)

```
val currentSelection: Selection?
```

The currently-selected content in the PDF, or null if nothing is selected

### firstVisiblePage

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)

```
val firstVisiblePage: Int
```

The first page in the viewport, including partially-visible pages. 0-indexed.

### firstVisiblePageOffset

```
val firstVisiblePageOffset: Offset
```

The `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` of the first visible page in the viewport in view coordinates.

### gestureState

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)

```
val gestureState: Int
```

State regarding whether the user is interacting with the PDF, one of `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#GESTURE_STATE_IDLE()`, `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#GESTURE_STATE_SETTLING()`, or `https://developer.android.com/reference/kotlin/androidx/pdf/compose/PdfViewerState#GESTURE_STATE_INTERACTING()`

### visiblePagesCount

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)

```
val visiblePagesCount: Int
```

The number of pages visible in the viewport, including partially visible pages.

### zoom

Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)

```
val zoom: Float
```

The zoom level of this view, as a factor of the content's natural size with when 1 pixel is equal to 1 PDF point.