# 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)

*** ** * ** ***


```
interface PdfLoader
```

<br />

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

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

## Summary

| ### Public functions |
|---|---|
| `suspend https://developer.android.com/reference/kotlin/androidx/pdf/PdfDocument` | `https://developer.android.com/reference/kotlin/androidx/pdf/PdfLoader#openDocument(android.net.Uri,kotlin.String)(uri: https://developer.android.com/reference/android/net/Uri.html, password: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?)` Asynchronously opens a `https://developer.android.com/reference/kotlin/androidx/pdf/PdfDocument` from the specified `https://developer.android.com/reference/android/net/Uri.html`. |
| `suspend https://developer.android.com/reference/kotlin/androidx/pdf/PdfDocument` | `https://developer.android.com/reference/kotlin/androidx/pdf/PdfLoader#openDocument(android.net.Uri,android.os.ParcelFileDescriptor,kotlin.String,androidx.pdf.RenderParams)( uri: https://developer.android.com/reference/android/net/Uri.html, fileDescriptor: https://developer.android.com/reference/android/os/ParcelFileDescriptor.html, password: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, renderParams: https://developer.android.com/reference/kotlin/androidx/pdf/RenderParams )` Asynchronously opens a `https://developer.android.com/reference/kotlin/androidx/pdf/PdfDocument` from the specified `https://developer.android.com/reference/kotlin/androidx/pdf/PdfLoader#openDocument(android.net.Uri,android.os.ParcelFileDescriptor,kotlin.String,androidx.pdf.RenderParams)`. |

## Public functions

### openDocument

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

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

| Parameters |
|---|---|
| `uri: https://developer.android.com/reference/android/net/Uri.html` | The URI of the PDF document to open. |
| `password: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html? = null` | (Optional) The password to unlock the document if it is encrypted. |

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

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/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

```
suspend fun openDocument(
    uri: Uri,
    fileDescriptor: ParcelFileDescriptor,
    password: String? = null,
    renderParams: RenderParams = RenderParams(renderMode = RenderParams.RENDER_MODE_FOR_DISPLAY)
): PdfDocument
```

Asynchronously opens a `https://developer.android.com/reference/kotlin/androidx/pdf/PdfDocument` from the specified `https://developer.android.com/reference/kotlin/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/kotlin/androidx/pdf/PdfDocument`, and it should be closed using the document, unless an exception is thrown.

| Parameters |
|---|---|
| `uri: https://developer.android.com/reference/android/net/Uri.html` | This is used only as a unique identifier for the `https://developer.android.com/reference/kotlin/androidx/pdf/PdfDocument`. The source of truth for accessing file contents is in this case the `https://developer.android.com/reference/kotlin/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. |
| `fileDescriptor: https://developer.android.com/reference/android/os/ParcelFileDescriptor.html` | a `https://developer.android.com/reference/android/os/ParcelFileDescriptor.html` pointing at the PDF content to be opened. Must be seekable. |
| `password: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html? = null` | (Optional) The password to unlock the document if it is encrypted. |
| `renderParams: https://developer.android.com/reference/kotlin/androidx/pdf/RenderParams = RenderParams(renderMode = RenderParams.RENDER_MODE_FOR_DISPLAY)` | (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/kotlin/androidx/pdf/RenderParams` with `https://developer.android.com/reference/kotlin/androidx/pdf/RenderParams#renderMode()` = `https://developer.android.com/reference/kotlin/androidx/pdf/RenderParams#RENDER_MODE_FOR_DISPLAY()` will be used. |

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

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/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. |