PdfDocument


interface PdfDocument : Closeable

Known direct subclasses
EditablePdfDocument

Represents a PDF document that allows for editing.


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

Summary

Nested types

A source for retrieving bitmap representations of PDF pages.

Listener interface for receiving notifications when some regions of the PDF content are invalidated.

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.

Constants

const Long

Flag to include all types of form widgets in getFormWidgetInfos

const Long

Flag to include FormWidgetInfo.WIDGET_TYPE_CHECKBOX in getFormWidgetInfos

const Long

Flag to include FormWidgetInfo.WIDGET_TYPE_COMBOBOX in getFormWidgetInfos

const Long

Flag to include FormWidgetInfo.WIDGET_TYPE_LISTBOX in getFormWidgetInfos

const Long

Flag to include FormWidgetInfo.WIDGET_TYPE_PUSHBUTTON in getFormWidgetInfos

const Long

Flag to include FormWidgetInfo.WIDGET_TYPE_RADIOBUTTON in getFormWidgetInfos

const Long

Flag to include FormWidgetInfo.WIDGET_TYPE_SIGNATURE in getFormWidgetInfos

const Long

Flag to include FormWidgetInfo.WIDGET_TYPE_TEXTFIELD in getFormWidgetInfos

const Long

Flag to include FormWidgetInfo.WIDGET_TYPE_UNKNOWN in getFormWidgetInfos

const Long

Flag used with getPageInfo to exclude any additional information in the returned PageInfo

const Long

Flag used with getPageInfo to include form widget metadata in the PageInfo

const Int

Represents a PDF with form fields specified using the AcroForm spec

const Int

Represents a PDF with no form fields

const Int

Represents a PDF with form fields specified using the XFAF subset of the XFA spec

const Int

Represents a PDF with form fields specified using the entire XFA spec

Public functions

Unit

Adds a listener to receive notifications when some regions of the PDF content are invalidated.

suspend List<FormWidgetInfo>
getFormWidgetInfos(pageNum: Int, types: Long)

Returns the list of FormWidgetInfo on pageNum, optionally filtered by widget type.

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 PdfDocument.PageInfo
getPageInfo(pageNumber: Int, pageInfoFlags: Long)

Asynchronously retrieves information about the specified page.

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

Asynchronously retrieves information about a range of pages.

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

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.

Unit

Removes the listener from the list of listeners which are notified when some regions of the PDF content are invalidated.

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

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

Public properties

Int

The type of form present in the document.

Boolean

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

Int

The total number of pages in the document.

RenderParams

The render params used to determine the contents that will be rendered on the bitmap.

Uri

The URI of the document represented by this object

Inherited functions

From java.io.Closeable

Constants

FORM_WIDGET_INCLUDE_ALL_TYPES

Added in 1.0.0-alpha13
const val FORM_WIDGET_INCLUDE_ALL_TYPESLong

Flag to include all types of form widgets in getFormWidgetInfos

FORM_WIDGET_INCLUDE_CHECKBOX_TYPE

Added in 1.0.0-alpha13
const val FORM_WIDGET_INCLUDE_CHECKBOX_TYPELong

Flag to include FormWidgetInfo.WIDGET_TYPE_CHECKBOX in getFormWidgetInfos

FORM_WIDGET_INCLUDE_COMBOBOX_TYPE

Added in 1.0.0-alpha13
const val FORM_WIDGET_INCLUDE_COMBOBOX_TYPELong

Flag to include FormWidgetInfo.WIDGET_TYPE_COMBOBOX in getFormWidgetInfos

FORM_WIDGET_INCLUDE_LISTBOX_TYPE

Added in 1.0.0-alpha13
const val FORM_WIDGET_INCLUDE_LISTBOX_TYPELong

Flag to include FormWidgetInfo.WIDGET_TYPE_LISTBOX in getFormWidgetInfos

FORM_WIDGET_INCLUDE_PUSHBUTTON_TYPE

Added in 1.0.0-alpha13
const val FORM_WIDGET_INCLUDE_PUSHBUTTON_TYPELong

Flag to include FormWidgetInfo.WIDGET_TYPE_PUSHBUTTON in getFormWidgetInfos

FORM_WIDGET_INCLUDE_RADIOBUTTON_TYPE

Added in 1.0.0-alpha13
const val FORM_WIDGET_INCLUDE_RADIOBUTTON_TYPELong

Flag to include FormWidgetInfo.WIDGET_TYPE_RADIOBUTTON in getFormWidgetInfos

FORM_WIDGET_INCLUDE_SIGNATURE_TYPE

Added in 1.0.0-alpha13
const val FORM_WIDGET_INCLUDE_SIGNATURE_TYPELong

Flag to include FormWidgetInfo.WIDGET_TYPE_SIGNATURE in getFormWidgetInfos

FORM_WIDGET_INCLUDE_TEXTFIELD_TYPE

Added in 1.0.0-alpha13
const val FORM_WIDGET_INCLUDE_TEXTFIELD_TYPELong

Flag to include FormWidgetInfo.WIDGET_TYPE_TEXTFIELD in getFormWidgetInfos

FORM_WIDGET_INCLUDE_UNKNOWN_TYPE

Added in 1.0.0-alpha13
const val FORM_WIDGET_INCLUDE_UNKNOWN_TYPELong

Flag to include FormWidgetInfo.WIDGET_TYPE_UNKNOWN in getFormWidgetInfos

PAGE_INFO_EXCLUDE_FORM_WIDGETS

Added in 1.0.0-alpha13
const val PAGE_INFO_EXCLUDE_FORM_WIDGETS = 0: Long

Flag used with getPageInfo to exclude any additional information in the returned PageInfo

PAGE_INFO_INCLUDE_FORM_WIDGET

Added in 1.0.0-alpha13
const val PAGE_INFO_INCLUDE_FORM_WIDGETLong

Flag used with getPageInfo to include form widget metadata in the PageInfo

PDF_FORM_TYPE_ACRO_FORM

Added in 1.0.0-alpha13
const val PDF_FORM_TYPE_ACRO_FORM = 1: Int

Represents a PDF with form fields specified using the AcroForm spec

PDF_FORM_TYPE_NONE

Added in 1.0.0-alpha13
const val PDF_FORM_TYPE_NONE = 0: Int

Represents a PDF with no form fields

PDF_FORM_TYPE_XFA_FOREGROUND

Added in 1.0.0-alpha13
const val PDF_FORM_TYPE_XFA_FOREGROUND = 3: Int

Represents a PDF with form fields specified using the XFAF subset of the XFA spec

PDF_FORM_TYPE_XFA_FULL

Added in 1.0.0-alpha13
const val PDF_FORM_TYPE_XFA_FULL = 2: Int

Represents a PDF with form fields specified using the entire XFA spec

Public functions

addOnPdfContentInvalidatedListener

Added in 1.0.0-alpha13
fun addOnPdfContentInvalidatedListener(
    executor: Executor,
    listener: PdfDocument.OnPdfContentInvalidatedListener
): Unit

Adds a listener to receive notifications when some regions of the PDF content are invalidated.

Parameters
executor: Executor

The executor on which the listener's methods will be called.

listener: PdfDocument.OnPdfContentInvalidatedListener

The listener to add.

getFormWidgetInfos

suspend fun getFormWidgetInfos(
    pageNum: Int,
    types: Long = FORM_WIDGET_INCLUDE_ALL_TYPES
): List<FormWidgetInfo>

Returns the list of FormWidgetInfo on pageNum, optionally filtered by widget type.

Parameters
pageNum: Int

The page number (0-based).

types: Long = FORM_WIDGET_INCLUDE_ALL_TYPES

Bitmask to determine the types of form widgets to include in the result. Includes all types of form widgets by default.

Returns
List<FormWidgetInfo>

A list of FormWidgetInfo objects representing the form widgets of the specified types on the specified page.

getPageBitmapSource

Added in 1.0.0-alpha13
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.

getPageInfo

suspend fun getPageInfo(
    pageNumber: Int,
    pageInfoFlags: Long = PAGE_INFO_EXCLUDE_FORM_WIDGETS
): PdfDocument.PageInfo

Asynchronously retrieves information about the specified page.

Parameters
pageNumber: Int

The page number (0-based).

pageInfoFlags: Long = PAGE_INFO_EXCLUDE_FORM_WIDGETS

A bitmask for retrieving additional page information. Does not include any additional information by default.

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.

getPageInfos

suspend fun getPageInfos(
    pageRange: IntRange,
    pageInfoFlags: Long = PAGE_INFO_EXCLUDE_FORM_WIDGETS
): List<PdfDocument.PageInfo>

Asynchronously retrieves information about a range of pages.

Parameters
pageRange: IntRange

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

pageInfoFlags: Long = PAGE_INFO_EXCLUDE_FORM_WIDGETS

A bitmask for retrieving additional page information. Does not include any additional information by default.

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.

removeOnPdfContentInvalidatedListener

Added in 1.0.0-alpha13
fun removeOnPdfContentInvalidatedListener(
    listener: PdfDocument.OnPdfContentInvalidatedListener
): Unit

Removes the listener from the list of listeners which are notified when some regions of the PDF content are invalidated.

Parameters
listener: PdfDocument.OnPdfContentInvalidatedListener

The listener to remove.

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

formType

Added in 1.0.0-alpha13
val formTypeInt

The type of form present in the document.

See also
PdfDocument.FormType

for the supported types.

isLinearized

Added in 1.0.0-alpha13
val isLinearizedBoolean

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

pageCount

Added in 1.0.0-alpha13
val pageCountInt

The total number of pages in the document.

renderParams

Added in 1.0.0-alpha13
val renderParamsRenderParams

The render params used to determine the contents that will be rendered on the bitmap.

uri

Added in 1.0.0-alpha13
val uriUri

The URI of the document represented by this object