# PdfLoader

Artifact: [androidx.pdf:pdf-core](https://developer.android.com/jetpack/androidx/releases/pdf) [View Source](https://cs.android.com/search?q=file:androidx/pdf/PdfLoader.kt+class:androidx.pdf.PdfLoader) Added in [1.0.0-beta01](https://developer.android.com/jetpack/androidx/releases/pdf#1.0.0-beta01)

*** ** * ** ***


```
public interface PdfLoader
```

<br />

Known direct subclasses [SandboxedPdfLoader](https://developer.android.com/reference/androidx/pdf/SandboxedPdfLoader)

|---|---|
| `https://developer.android.com/reference/androidx/pdf/SandboxedPdfLoader` | A `https://developer.android.com/reference/androidx/pdf/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 `https://developer.android.com/reference/androidx/pdf/PdfDocument` representation.

## Summary

| ### Public methods |
|---|---|
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/pdf/PdfDocument` | `https://developer.android.com/reference/androidx/pdf/PdfLoader#openDocument(android.net.Uri,kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/net/Uri.html uri, https://developer.android.com/reference/java/lang/String.html password)` Asynchronously opens a `https://developer.android.com/reference/androidx/pdf/PdfDocument` from the specified `https://developer.android.com/reference/android/net/Uri.html`. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/pdf/PdfDocument` | `https://developer.android.com/reference/androidx/pdf/PdfLoader#openDocument(android.net.Uri,android.os.ParcelFileDescriptor,kotlin.String,androidx.pdf.RenderParams)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/net/Uri.html uri, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/ParcelFileDescriptor.html fileDescriptor, https://developer.android.com/reference/java/lang/String.html password, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/pdf/RenderParams renderParams )` Asynchronously opens a `https://developer.android.com/reference/androidx/pdf/PdfDocument` from the specified `https://developer.android.com/reference/androidx/pdf/PdfLoader#openDocument(android.net.Uri,android.os.ParcelFileDescriptor,kotlin.String,androidx.pdf.RenderParams)`. |

## Public methods

### openDocument

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

Asynchronously opens a `https://developer.android.com/reference/androidx/pdf/PdfDocument` from the specified `https://developer.android.com/reference/android/net/Uri.html`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/net/Uri.html uri` | The URI of the PDF document to open. |
| `https://developer.android.com/reference/java/lang/String.html password` | (Optional) The password to unlock the document if it is encrypted. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/pdf/PdfDocument` | The opened `https://developer.android.com/reference/androidx/pdf/PdfDocument`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/pdf/PdfPasswordException` | If the provided password is incorrect. |
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs while opening the document. |

### openDocument

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

Asynchronously opens a `https://developer.android.com/reference/androidx/pdf/PdfDocument` from the specified `https://developer.android.com/reference/androidx/pdf/PdfLoader#openDocument(android.net.Uri,android.os.ParcelFileDescriptor,kotlin.String,androidx.pdf.RenderParams)`. The file descriptor will become owned by the `https://developer.android.com/reference/androidx/pdf/PdfDocument`, and it should be closed using the document, unless an exception is thrown.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/net/Uri.html uri` | This is used only as a unique identifier for the `https://developer.android.com/reference/androidx/pdf/PdfDocument`. The source of truth for accessing file contents is in this case the `https://developer.android.com/reference/androidx/pdf/PdfLoader#openDocument(android.net.Uri,android.os.ParcelFileDescriptor,kotlin.String,androidx.pdf.RenderParams)`. If you don't have access to the `https://developer.android.com/reference/android/net/Uri.html` 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. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/ParcelFileDescriptor.html fileDescriptor` | a `https://developer.android.com/reference/android/os/ParcelFileDescriptor.html` pointing at the PDF content to be opened. Must be seekable. |
| `https://developer.android.com/reference/java/lang/String.html password` | (Optional) The password to unlock the document if it is encrypted. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/pdf/RenderParams renderParams` | (Optional) Represents a set of parameters that will be used to render a page of the document. If not provided, the default `https://developer.android.com/reference/androidx/pdf/RenderParams` with `https://developer.android.com/reference/androidx/pdf/RenderParams#renderMode()` = `https://developer.android.com/reference/androidx/pdf/RenderParams#RENDER_MODE_FOR_DISPLAY()` will be used. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/pdf/PdfDocument` | The opened `https://developer.android.com/reference/androidx/pdf/PdfDocument`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/pdf/PdfPasswordException` | If the provided password is incorrect. |
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs while opening the document. |