PdfLoader


interface PdfLoader

Known direct subclasses
SandboxedPdfLoader

A PdfLoader implementation that opens PDF documents through a sandboxed Android service.


Provides an abstraction for asynchronously opening PDF documents from a Uri. Implementations of this interface are responsible for handling the retrieval, decryption (if necessary), and creation of a PdfDocument representation.

Summary

Public functions

suspend PdfDocument
openDocument(uri: Uri, password: String?)

Asynchronously opens a PdfDocument from the specified Uri.

suspend PdfDocument
openDocument(
    uri: Uri,
    fileDescriptor: ParcelFileDescriptor,
    password: String?
)

Asynchronously opens a PdfDocument from the specified fileDescriptor.

Public functions

openDocument

suspend fun openDocument(uri: Uri, password: String? = null): PdfDocument

Asynchronously opens a PdfDocument from the specified Uri.

Parameters
uri: Uri

The URI of the PDF document to open.

password: String? = null

(Optional) The password to unlock the document if it is encrypted.

Returns
PdfDocument

The opened PdfDocument.

Throws
androidx.pdf.PdfPasswordException

If the provided password is incorrect.

java.io.IOException

If an error occurs while opening the document.

openDocument

suspend fun openDocument(
    uri: Uri,
    fileDescriptor: ParcelFileDescriptor,
    password: String? = null
): PdfDocument

Asynchronously opens a PdfDocument from the specified fileDescriptor. The file descriptor will become owned by the PdfDocument, and it should be closed using the document, unless an exception is thrown.

Parameters
uri: Uri

This is used only as a unique identifier for the PdfDocument. The source of truth for accessing file contents is in this case the fileDescriptor. If you don't have access to the Uri which produced the file descriptor, or the file descriptor was not produced by opening a URI, it's acceptable to provide a "fake" one here, so long as the value uniquely identifies the document.

fileDescriptor: ParcelFileDescriptor

a ParcelFileDescriptor pointing at the PDF content to be opened. Must be seekable.

password: String? = null

(Optional) The password to unlock the document if it is encrypted.

Returns
PdfDocument

The opened PdfDocument.

Throws
androidx.pdf.PdfPasswordException

If the provided password is incorrect.

java.io.IOException

If an error occurs while opening the document.