PdfView
open class PdfView : ViewGroup
A View for presenting PDF content, represented by PdfDocument.
This View supports zooming, scrolling, and flinging. Zooming is supported via pinch gesture, quick scale gesture, and double tap to zoom in or snap back to fitting the page width inside its bounds. Zoom can be changed using the zoom property, which is notably distinct from View.getScaleX / View.getScaleY. Scroll position is based on the View.getScrollX / View.getScrollY properties.
This inherits ViewGroup but does not support adding arbitrary children via addView or in a layout.
Summary
Nested types |
|---|
interface PdfView.LinkClickListenerListener interface for handling clicks on links in a PDF document. |
interface PdfView.OnGestureStateChangedListenerListener interface to receive callbacks when the PdfView starts and stops being affected by an external input like user touch. |
interface PdfView.OnSelectionChangedListenerListener interface to receive updates when the |
interface PdfView.OnViewportChangedListenerListener interface to receive changes to the viewport, i.e. the window of visible PDF content |
interface PdfView.SelectionMenuItemPreparerInterface to customize the set of actions in the selection menu |
Constants |
|
|---|---|
const Int |
The PdfView is not currently being affected by an outside input, e.g. user touch |
const Int |
The PdfView is currently being affected by an outside input, e.g. user touch |
const Int |
The PdfView is currently animating to a final position while not under outside control, e.g. settling on a final position following a fling gesture. |
const Int |
Vertically aligns the page to the center of the PdfView. |
const Int |
Vertically aligns the page to the top of the PdfView. |
Public constructors |
|---|
PdfView(context: Context, attrs: AttributeSet?, defStyle: Int) |
Public functions |
|
|---|---|
Unit |
Adds the specified listener to the list of listeners that will be notified of changes in state with respect to this PdfView being affected by an external input, e.g. user touch. |
Unit |
Adds the specified listener to the list of listeners that will be notified of selection change events. |
Unit |
Adds the specified listener to the list of listeners that will be notified of viewport change events. |
Unit |
addSelectionMenuItemPreparer(Adds the specified listener to the chain of |
open Unit |
|
open Unit |
|
open Unit |
addView(child: View?, params: ViewGroup.LayoutParams?) |
open Unit |
addView(child: View?, index: Int, params: ViewGroup.LayoutParams?) |
open Unit |
|
Unit |
Clears the current selection, if one exists. |
open Unit |
|
open Boolean |
dispatchKeyEvent(event: KeyEvent?)Prioritizes standard keyboard shortcuts over accessibility-specific handling of certain keys. |
open Boolean |
onGenericMotionEvent(event: MotionEvent?) |
open Boolean |
onTouchEvent(event: MotionEvent?) |
PointF? |
pdfToViewPoint(pdfPoint: PdfPoint)Returns the View coordinate location of |
Unit |
Removes the specified listener from the list of listeners that will be notified of changes in state with respect to this PdfView being affected by an external input, e.g. user touch. |
Unit |
Removes the specified listener from the list of listeners that will be notified of selection change events. |
Unit |
Removes the specified listener from the list of listeners that will be notified of viewport change events. |
Unit |
removeSelectionMenuItemPreparer(Removes the specified listener from the chain of |
open Unit |
|
open Unit |
|
Unit |
scrollToPage(pageNum: Int)Scrolls to the 0-indexed |
Unit |
scrollToPosition(position: PdfPoint)Scrolls to |
Unit |
setHighlights(highlights: List<Highlight>)Applies a set of |
Unit |
setLinkClickListener(listener: PdfView.LinkClickListener?)Registers |
PdfPoint? |
viewToPdfPoint(viewPoint: PointF)Returns the |
PdfPoint? |
viewToPdfPoint(x: Float, y: Float)Returns the |
Protected functions |
|
|---|---|
open Int |
|
open Int |
|
open Boolean |
dispatchHoverEvent(event: MotionEvent?) |
open Unit |
|
open Unit |
onConfigurationChanged(newConfig: Configuration?) |
open Unit |
|
open Unit |
|
open Unit |
onFocusChanged( |
open Unit |
|
open Unit |
onRestoreInstanceState(state: Parcelable?) |
open Parcelable? |
|
open Unit |
onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int) |
open Unit |
onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) |
open Unit |
onWindowVisibilityChanged(visibility: Int) |
Public properties |
|
|---|---|
Selection? |
The currently selected PDF content, as |
Drawable |
|
Int |
|
Drawable |
|
Int |
|
Int |
The first page in the viewport, including partially-visible pages. |
Int |
The current state of the PDF view with respect to external inputs, e.g. user touch. |
Float |
The maximum scaling factor that can be applied to this View using the |
Float |
The minimum scaling factor that can be applied to this View using the |
PdfDocument? |
Supply a |
Int |
Controls the vertical alignment of a page within the |
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 = 0: Int
The PdfView is not currently being affected by an outside input, e.g. user touch
GESTURE_STATE_INTERACTING
const val GESTURE_STATE_INTERACTING = 1: Int
The PdfView is currently being affected by an outside input, e.g. user touch
GESTURE_STATE_SETTLING
const val GESTURE_STATE_SETTLING = 2: Int
The PdfView is currently animating to a final position while not under outside control, e.g. settling on a final position following a fling gesture.
VERTICAL_ALIGNMENT_CENTER
const val VERTICAL_ALIGNMENT_CENTER = 1: Int
Vertically aligns the page to the center of the PdfView.
This alignment is used when the page is scaled to fit the view's width, and the resulting page height is less than the view's height. The top of the page will be positioned at the center of the PdfView. If the scaled page height is greater than the height of PdfView, the top of the first page is always at the top of the view by default, and this alignment will have no effect.
VERTICAL_ALIGNMENT_TOP
const val VERTICAL_ALIGNMENT_TOP = 0: Int
Vertically aligns the page to the top of the PdfView.
This alignment is used when the page is scaled to fit the view's width, and the resulting page height is less than the view's height. The top of the page will be positioned at the top of the PdfView. If the scaled page height is greater than the height of PdfView, the top of the first page is always at the top of the view by default, and this alignment will have no effect.
Public constructors
PdfView
PdfView(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0)
Public functions
addOnGestureStateChangedListener
fun addOnGestureStateChangedListener(
listener: PdfView.OnGestureStateChangedListener
): Unit
Adds the specified listener to the list of listeners that will be notified of changes in state with respect to this PdfView being affected by an external input, e.g. user touch.
| Parameters | |
|---|---|
listener: PdfView.OnGestureStateChangedListener |
listener to notify when interaction state change events occur |
| See also | |
|---|---|
removeOnGestureStateChangedListener |
addOnSelectionChangedListener
fun addOnSelectionChangedListener(
listener: PdfView.OnSelectionChangedListener
): Unit
Adds the specified listener to the list of listeners that will be notified of selection change events.
| Parameters | |
|---|---|
listener: PdfView.OnSelectionChangedListener |
listener to notify when selection change events occur |
| See also | |
|---|---|
removeOnSelectionChangedListener |
addOnViewportChangedListener
fun addOnViewportChangedListener(
listener: PdfView.OnViewportChangedListener
): Unit
Adds the specified listener to the list of listeners that will be notified of viewport change events.
| Parameters | |
|---|---|
listener: PdfView.OnViewportChangedListener |
listener to add |
addSelectionMenuItemPreparer
fun addSelectionMenuItemPreparer(
selectionMenuItemPreparer: PdfView.SelectionMenuItemPreparer
): Unit
Adds the specified listener to the chain of SelectionMenuItemPreparer. The listener will be invoked in the order they've been added.
| Parameters | |
|---|---|
selectionMenuItemPreparer: PdfView.SelectionMenuItemPreparer |
: The |
| See also | |
|---|---|
removeSelectionMenuItemPreparer |
clearCurrentSelection
fun clearCurrentSelection(): Unit
Clears the current selection, if one exists. No-op if there is no current Selection
dispatchKeyEvent
open fun dispatchKeyEvent(event: KeyEvent?): Boolean
Prioritizes standard keyboard shortcuts over accessibility-specific handling of certain keys. This ensures a consistent experience for all users, where shortcuts like D-pad scrolling work irrespective of whether accessibility is enabled or not, as both externalInputManager and pdfViewAccessibilityManager are capable of handling certain key events.
pdfToViewPoint
fun pdfToViewPoint(pdfPoint: PdfPoint): PointF?
Returns the View coordinate location of pdfPoint, or null if that PDF content has not been laid out yet.
removeOnGestureStateChangedListener
fun removeOnGestureStateChangedListener(
listener: PdfView.OnGestureStateChangedListener
): Unit
Removes the specified listener from the list of listeners that will be notified of changes in state with respect to this PdfView being affected by an external input, e.g. user touch.
| Parameters | |
|---|---|
listener: PdfView.OnGestureStateChangedListener |
listener to remove |
removeOnSelectionChangedListener
fun removeOnSelectionChangedListener(
listener: PdfView.OnSelectionChangedListener
): Unit
Removes the specified listener from the list of listeners that will be notified of selection change events.
| Parameters | |
|---|---|
listener: PdfView.OnSelectionChangedListener |
listener to remove |
removeOnViewportChangedListener
fun removeOnViewportChangedListener(
listener: PdfView.OnViewportChangedListener
): Unit
Removes the specified listener from the list of listeners that will be notified of viewport change events.
| Parameters | |
|---|---|
listener: PdfView.OnViewportChangedListener |
listener to remove |
removeSelectionMenuItemPreparer
fun removeSelectionMenuItemPreparer(
selectionMenuItemPreparer: PdfView.SelectionMenuItemPreparer
): Unit
Removes the specified listener from the chain of SelectionMenuItemPreparer.
| Parameters | |
|---|---|
selectionMenuItemPreparer: PdfView.SelectionMenuItemPreparer |
: The |
scrollToPage
fun scrollToPage(pageNum: Int): Unit
Scrolls to the 0-indexed pageNum, optionally animating the scroll
This View cannot scroll to a page until it knows its dimensions. If pageNum is distant from the currently-visible page in a large PDF, there may be some delay while dimensions are being loaded from the PDF.
scrollToPosition
fun scrollToPosition(position: PdfPoint): Unit
Scrolls to position, aligns vertically to center, optionally animating the scroll
This View cannot scroll to a page until it knows its dimensions. If position is distant from the currently-visible page in a large PDF, there may be some delay while dimensions are being loaded from the PDF.
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.
setLinkClickListener
fun setLinkClickListener(listener: PdfView.LinkClickListener?): Unit
Registers listener as the callback to be invoked when an external link in the PDF is clicked. Supply null to clear any current listener.
viewToPdfPoint
fun viewToPdfPoint(viewPoint: PointF): PdfPoint?
Returns the PdfPoint corresponding to viewPoint in View coordinates, or null if no PDF content has been laid out at viewPoint
viewToPdfPoint
fun viewToPdfPoint(x: Float, y: Float): PdfPoint?
Returns the PdfPoint corresponding to (x, y)in View coordinates, or null if no PDF content has been laid out at that point.
Protected functions
onFocusChanged
protected open fun onFocusChanged(
gainFocus: Boolean,
direction: Int,
previouslyFocusedRect: Rect?
): Unit
Public properties
currentSelection
val currentSelection: Selection?
The currently selected PDF content, as Selection, or 'null' if no content is currently selected.
fastScrollPageIndicatorBackgroundDrawable
var fastScrollPageIndicatorBackgroundDrawable: Drawable
fastScrollVerticalThumbDrawable
var fastScrollVerticalThumbDrawable: Drawable
firstVisiblePage
val firstVisiblePage: Int
The first page in the viewport, including partially-visible pages. 0-indexed.
gestureState
val gestureState: Int
The current state of the PDF view with respect to external inputs, e.g. user touch. Returns one of GESTURE_STATE_IDLE, GESTURE_STATE_INTERACTING, or GESTURE_STATE_SETTLING
maxZoom
var maxZoom: Float
The maximum scaling factor that can be applied to this View using the zoom property
minZoom
var minZoom: Float
The minimum scaling factor that can be applied to this View using the zoom property
pdfDocument
var pdfDocument: PdfDocument?
Supply a PdfDocument to process the PDF content for rendering
verticalAlignment
var verticalAlignment: Int
Controls the vertical alignment of a page within the PdfView.
This attribute aligns a page within the view when the page's height is smaller than the view's height. In this state, scrolling and panning are disabled as the entire page is visible. However, zooming in will re-enable scrolling and panning, aligning page to the top.
| See also | |
|---|---|
PdfView.VerticalAlignment |
visiblePagesCount
val visiblePagesCount: Int
The number of pages visible in the viewport, including partially visible pages
zoom
var 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. Will always be clamped within (minZoom, maxZoom)