PdfViewerState
@ExperimentalPdfApi
class PdfViewerState
A state object that can be hoisted to observe and control PdfViewer zoom, scroll, and content position.
Summary
Constants |
|
|---|---|
const Int |
|
const Int |
|
const Int |
|
Public constructors |
|---|
Public functions |
|
|---|---|
Unit |
Clears the current selection, if one exists. |
Offset? |
getVisiblePageOffset(visiblePageNumber: @IntRange(from = 0) Int)Returns the |
Offset |
pdfPointToVisibleOffset(pdfPoint: PdfPoint)Returns the View coordinate location of |
suspend Unit |
scrollToPage(pageNum: @IntRange(from = 0) Int)Centers the page at |
suspend Unit |
scrollToPosition(position: PdfPoint)Centers the location described by |
Unit |
setHighlights(highlights: List<Highlight>)Applies a set of |
PdfPoint? |
visibleOffsetToPdfPoint(offset: Offset)Returns the |
suspend Unit |
zoomScroll(block: PdfZoomScrollScope.() -> Unit)Call this function to take control of zoom and scroll, and gain the ability to send zoom and / or scroll events via |
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 |
The |
Int |
State regarding whether the user is interacting with the PDF, one of |
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_IDLE: Int
PdfViewer is not currently being affected by an outside input, e.g. user touch
| See also | |
|---|---|
gestureState |
GESTURE_STATE_INTERACTING
const val GESTURE_STATE_INTERACTING: Int
PdfViewer is currently being affected by an outside input, e.g. user touch
| See also | |
|---|---|
gestureState |
GESTURE_STATE_SETTLING
const val GESTURE_STATE_SETTLING: 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.
| See also | |
|---|---|
gestureState |
Public constructors
Public functions
clearCurrentSelection
fun clearCurrentSelection(): Unit
Clears the current selection, if one exists. No-op if there is no current Selection
getVisiblePageOffset
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
fun pdfPointToVisibleOffset(pdfPoint: PdfPoint): Offset
Returns the View coordinate location of pdfPoint, or Offset.Unspecified 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
suspend fun scrollToPage(pageNum: @IntRange(from = 0) Int): Unit
Centers the page at pageNum in the viewport.
scrollToPosition
suspend fun scrollToPosition(position: PdfPoint): Unit
Centers the location described by position in the viewport
setHighlights
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
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
val currentSelection: Selection?
The currently-selected content in the PDF, or null if nothing is selected
firstVisiblePage
val firstVisiblePage: Int
The first page in the viewport, including partially-visible pages. 0-indexed.
firstVisiblePageOffset
val firstVisiblePageOffset: Offset
The Offset of the first visible page in the viewport in view coordinates.
gestureState
val gestureState: Int
State regarding whether the user is interacting with the PDF, one of GESTURE_STATE_IDLE, GESTURE_STATE_SETTLING, or GESTURE_STATE_INTERACTING
visiblePagesCount
val visiblePagesCount: Int
The number of pages visible in the viewport, including partially visible pages.
zoom
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.