PdfViewerState

class PdfViewerState


A state object that can be hoisted to observe and control PdfViewer zoom, scroll, and content position.

Summary

Constants

const Int

PdfViewer is not currently being affected by an outside input, e.g. user touch

const Int

PdfViewer is currently being affected by an outside input, e.g. user touch

const Int

PdfViewer 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

Public functions

Unit

Clears the current selection, if one exists.

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

Returns the Offset of the page at visiblePageNumber, or null if the provided page number is not currently visible.

Offset?

Returns the View coordinate location of pdfPoint, or null if that PDF content has not been laid out yet.

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

Centers the page at pageNum in the viewport.

suspend Unit

Centers the location described by position in the viewport

Unit

Applies a set of Highlight to be drawn over this PDF.

PdfPoint?

Returns the PdfPoint corresponding to offset in Compose coordinates, or null if no PDF content has been laid out at this Offset.

suspend Unit

Call this function to take control of zoom and scroll, and gain the ability to send zoom and / or scroll events via PdfZoomScrollScope.

Public properties

Selection?

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

Int

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

Offset
Int

State regarding whether the user is interacting with the PDF, one of GESTURE_STATE_IDLE, GESTURE_STATE_SETTLING, or GESTURE_STATE_INTERACTING

Int

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

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.

Constants

GESTURE_STATE_IDLE

const val GESTURE_STATE_IDLEInt

PdfViewer is not currently being affected by an outside input, e.g. user touch

See also
gestureState

GESTURE_STATE_INTERACTING

const val GESTURE_STATE_INTERACTINGInt

PdfViewer is currently being affected by an outside input, e.g. user touch

See also
gestureState

GESTURE_STATE_SETTLING

const val GESTURE_STATE_SETTLINGInt

PdfViewer 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
gestureState

Public constructors

PdfViewerState

Added in 1.0.0-alpha10
PdfViewerState()

Public functions

clearSelection

Added in 1.0.0-alpha10
fun clearSelection(): Unit

Clears the current selection, if one exists. No-op if there is no current Selection

getVisiblePageOffset

Added in 1.0.0-alpha10
fun getVisiblePageOffset(visiblePageNumber: @IntRange(from = 0) Int): Offset?

Returns the Offset of the page at visiblePageNumber, or null if the provided page number is not currently visible.

pdfPointToVisibleOffset

Added in 1.0.0-alpha10
fun pdfPointToVisibleOffset(pdfPoint: PdfPoint): Offset?

Returns the View coordinate location of pdfPoint, or null if that PDF content has not been laid out yet.

Returns Offset.Unspecified if this PdfViewerState is not yet associated with a PdfViewer, or if the PdfViewer is not associated with a androidx.pdf.PdfDocument

scrollToPage

Added in 1.0.0-alpha10
suspend fun scrollToPage(pageNum: @IntRange(from = 0) Int): Unit

Centers the page at pageNum in the viewport.

scrollToPosition

Added in 1.0.0-alpha10
suspend fun scrollToPosition(position: PdfPoint): Unit

Centers the location described by position in the viewport

setHighlights

Added in 1.0.0-alpha10
fun setHighlights(highlights: List<Highlight>): Unit

Applies a set of Highlight to be drawn over this PDF. Each Highlight may be a different color. This overrides any previous highlights, there is no merging of new and previous values. highlights are defensively copied and the list or its contents may be modified after providing it here.

visibleOffsetToPdfPoint

fun visibleOffsetToPdfPoint(offset: Offset): PdfPoint?

Returns the PdfPoint corresponding to offset in Compose coordinates, or null if no PDF content has been laid out at this Offset.

Returns null if this PdfViewerState is not yet associated with a PdfViewer, or if the PdfViewer is not associated with a androidx.pdf.PdfDocument

zoomScroll

Added in 1.0.0-alpha10
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 PdfZoomScrollScope. All actions that change the logical zoom and / or scroll position must be performed within a zoomScroll block, even if they don't call other methods on this object in order to guarantee that mutual exclusion is enforced.

If zoomScroll is called from elsewhere, this will be cancelled.

Public properties

currentSelection

Added in 1.0.0-alpha10
val currentSelectionSelection?

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

firstVisiblePage

Added in 1.0.0-alpha10
val firstVisiblePageInt

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

firstVisiblePageOffset

val firstVisiblePageOffsetOffset

gestureState

Added in 1.0.0-alpha10
val gestureStateInt

State regarding whether the user is interacting with the PDF, one of GESTURE_STATE_IDLE, GESTURE_STATE_SETTLING, or GESTURE_STATE_INTERACTING

visiblePagesCount

Added in 1.0.0-alpha10
val visiblePagesCountInt

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

zoom

Added in 1.0.0-alpha10
val zoomFloat

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.