PDFView

class PDFView(context: Context?, attrs: AttributeSet?) : RelativeLayout

A view for displaying and interacting with PDF documents. It supports features like animation, zoom, caching, and swiping.

The PDF document is rendered as if we want to draw all pages side-by-side, with only the visible portions actually drawn on the screen. All parts are rendered at the same size to optimize performance and allow for interruption of native rendering. Parts are loaded when the offset or zoom level changes.

Constructors

Link copied to clipboard
constructor(context: Context?, attrs: AttributeSet?)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The index of the current sequence

Link copied to clipboard

If you picture all the pages side by side in their optimal width, and taking into account the zoom level, the current offset is the position of the left border of the screen in this big picture

Link copied to clipboard

If you picture all the pages side by side in their optimal width, and taking into account the zoom level, the current offset is the position of the left border of the screen in this big picture

Link copied to clipboard

Returns null if document is not loaded

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Get current position as ratio of document length to visible area. 0 means that document start is visible, 1 that document end is visible

Link copied to clipboard

Will be empty until document is loaded

Link copied to clipboard
var zoom: Float

The zoom level, always >= 1

Functions

Link copied to clipboard
open override fun canScrollHorizontally(direction: Int): Boolean
Link copied to clipboard
open override fun canScrollVertically(direction: Int): Boolean
Link copied to clipboard
open override fun computeScroll()

Handle fling animation

Link copied to clipboard

Checks if whole document can be displayed on screen, doesn't include zoom

Link copied to clipboard
fun enqueue(pdfRequest: PdfRequest)
Link copied to clipboard
fun fitToWidth(page: Int)
Link copied to clipboard
fun getLinks(page: Int): List<Link>

Will be empty until document is loaded

Link copied to clipboard
fun getPageAtPositionOffset(positionOffset: Float): Int

Get page number at given offset

Link copied to clipboard
fun getPageSize(pageIndex: Int): SizeF
Link copied to clipboard
fun jumpTo(page: Int, withAnimation: Boolean = false)

Go to the given page.

Link copied to clipboard
fun moveRelativeTo(dx: Float, dy: Float)

Move relatively to the current position.

Link copied to clipboard
fun recycle()
Link copied to clipboard
fun setPositionOffset(progress: Float, moveHandle: Boolean = false)
Link copied to clipboard
fun showPage(pageNb: Int)
Link copied to clipboard
fun stopFling()
Link copied to clipboard
fun zoomCenteredRelativeTo(dzoom: Float, pivot: PointF)
Link copied to clipboard
fun zoomCenteredTo(zoom: Float, pivot: PointF)

Change the zoom level, relatively to a pivot point. It will call moveTo() to make sure the given point stays in the middle of the screen.

Link copied to clipboard
fun zoomWithAnimation(centerX: Float, centerY: Float, scale: Float)

Inherited functions

Link copied to clipboard
inline fun PDFView.load(uri: Uri, builder: PdfRequest.Builder.() -> Unit = {})

Load PDF from a URI. Useful for content providers.

inline fun PDFView.load(source: DocumentSource, builder: PdfRequest.Builder.() -> Unit = {})

Load PDF using custom DocumentSource.

inline fun PDFView.load(file: File, builder: PdfRequest.Builder.() -> Unit = {})

Load PDF from a file.

inline fun PDFView.load(stream: InputStream, builder: PdfRequest.Builder.() -> Unit = {})

Load PDF from an {@link InputStream}. The stream is converted to a byte array, since native code does not support direct stream handling.

inline fun PDFView.load(bytes: ByteArray, builder: PdfRequest.Builder.() -> Unit = {})

Load PDF from a byte array. Document is not saved on disk.

inline fun PDFView.load(assetName: String, builder: PdfRequest.Builder.() -> Unit = {})

Load PDF from the assets file.