PdfLoader


public 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 methods

abstract @NonNull PdfDocument
openDocument(@NonNull Uri uri, String password)

Asynchronously opens a PdfDocument from the specified Uri.

abstract @NonNull PdfDocument
openDocument(
    @NonNull Uri uri,
    @NonNull ParcelFileDescriptor fileDescriptor,
    String password
)

Asynchronously opens a PdfDocument from the specified fileDescriptor.

Public methods

openDocument

abstract @NonNull PdfDocument openDocument(@NonNull Uri uri, String password)

Asynchronously opens a PdfDocument from the specified Uri.

Parameters
@NonNull Uri uri

The URI of the PDF document to open.

String password

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

Returns
@NonNull 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

abstract @NonNull PdfDocument openDocument(
    @NonNull Uri uri,
    @NonNull ParcelFileDescriptor fileDescriptor,
    String password
)

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
@NonNull 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.

@NonNull ParcelFileDescriptor fileDescriptor

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

String password

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

Returns
@NonNull 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.