PdfDocument


interface PdfDocument : Closeable


Represents a PDF document and provides methods to interact with its content.

Summary

Nested types

A source for retrieving bitmap representations of PDF pages.

Represents information about a single page in the PDF document.

Represents the combined text and image content within a single page of a PDF document.

Represents the links within a single page of a PDF document.

Public functions

PdfDocument.BitmapSource
getPageBitmapSource(pageNumber: Int)

Gets a BitmapSource for retrieving bitmap representations of the specified page.

suspend PdfDocument.PdfPageContent?
getPageContent(pageNumber: Int)

Asynchronously retrieves the content (text and images) of the specified page.

suspend PdfDocument.PageInfo
getPageInfo(pageNumber: Int)

Asynchronously retrieves information about the specified page.

suspend List<PdfDocument.PageInfo>
getPageInfos(pageRange: IntRange)

Asynchronously retrieves information about a range of pages.

suspend PdfDocument.PdfPageLinks
getPageLinks(pageNumber: Int)

Asynchronously retrieves the links (Go To and external) present on the specified page.

suspend PageSelection?
getSelectionBounds(pageNumber: Int, start: PointF, stop: PointF)

Asynchronously retrieves the selection bounds (in PDF coordinates) for the specified text selection.

suspend SparseArray<List<PageMatchBounds>>
searchDocument(query: String, pageRange: IntRange)

Asynchronously searches the document for the specified query within a range of pages.

Public properties

Boolean

Indicates whether the document is linearized (optimized for fast web viewing).

Int

The total number of pages in the document.

Uri

The URI of the document represented by this object

Inherited functions

From java.io.Closeable

Public functions

getPageBitmapSource

Added in 1.0.0-alpha10
fun getPageBitmapSource(pageNumber: Int): PdfDocument.BitmapSource

Gets a BitmapSource for retrieving bitmap representations of the specified page.

Parameters
pageNumber: Int

The page number (0-based).

Returns
PdfDocument.BitmapSource

A BitmapSource for the specified page, or null if the page number is invalid.

getPageContent

suspend fun getPageContent(pageNumber: Int): PdfDocument.PdfPageContent?

Asynchronously retrieves the content (text and images) of the specified page.

Parameters
pageNumber: Int

The page number (0-based).

Returns
PdfDocument.PdfPageContent?

A PdfPageContent object representing the page's content.

getPageInfo

suspend fun getPageInfo(pageNumber: Int): PdfDocument.PageInfo

Asynchronously retrieves information about the specified page.

Parameters
pageNumber: Int

The page number (0-based).

Returns
PdfDocument.PageInfo

A PageInfo object containing information about the page.

getPageInfos

suspend fun getPageInfos(pageRange: IntRange): List<PdfDocument.PageInfo>

Asynchronously retrieves information about a range of pages.

Parameters
pageRange: IntRange

The range of page numbers (0-based, inclusive).

Returns
List<PdfDocument.PageInfo>

A list of PageInfo objects, one for each page in the range.

getPageLinks

suspend fun getPageLinks(pageNumber: Int): PdfDocument.PdfPageLinks

Asynchronously retrieves the links (Go To and external) present on the specified page.

Parameters
pageNumber: Int

The page number (0-based).

Returns
PdfDocument.PdfPageLinks

A PdfPageLinks object representing the page's links.

getSelectionBounds

suspend fun getSelectionBounds(pageNumber: Int, start: PointF, stop: PointF): PageSelection?

Asynchronously retrieves the selection bounds (in PDF coordinates) for the specified text selection.

Parameters
pageNumber: Int

The page on which text to be selected.

start: PointF

The starting point of the text selection.

stop: PointF

The ending point of the text selection.

Returns
PageSelection?

A PageSelection object representing the selection bounds on the page.

searchDocument

suspend fun searchDocument(query: String, pageRange: IntRange): SparseArray<List<PageMatchBounds>>

Asynchronously searches the document for the specified query within a range of pages.

Parameters
query: String

The search query string.

pageRange: IntRange

The range of page numbers (0-based, inclusive) to search within.

Returns
SparseArray<List<PageMatchBounds>>

A SparseArray mapping page numbers to lists of PageMatchBounds objects representing the search results on each page.

Public properties

isLinearized

Added in 1.0.0-alpha10
val isLinearizedBoolean

Indicates whether the document is linearized (optimized for fast web viewing).

pageCount

Added in 1.0.0-alpha10
val pageCountInt

The total number of pages in the document.

uri

Added in 1.0.0-alpha10
val uriUri

The URI of the document represented by this object