SandboxedPdfLoader
class SandboxedPdfLoader : PdfLoader
A PdfLoader implementation that opens PDF documents through a sandboxed Android service.
This class establishes a connection with the PdfDocumentServiceImpl bound service and attempts to load a PDF document using the PdfRenderer. If successful, it returns a SandboxedPdfDocument instance, which provides a remote interface for interacting with the document.
The loading process involves:
-
Establishing a connection with the service using a
PdfServiceConnection. -
Opening a
ParcelFileDescriptorfor the PDF document. -
Passing the file descriptor to the service for loading and rendering.
-
Creating a
SandboxedPdfDocumentinstance upon successful loading.
Summary
Public companion functions |
|
|---|---|
PdfSandboxHandle |
startInitialization(context: Context)Prepares sandboxing PDF resources ahead of any document operations, to reduce latency during the interaction with the |
Public constructors |
|---|
SandboxedPdfLoader(context: Context, coroutineContext: CoroutineContext)Creates a new |
Public functions |
|
|---|---|
open suspend PdfDocument |
openDocument(uri: Uri, password: String?)Asynchronously opens a |
open suspend PdfDocument |
openDocument(Asynchronously opens a |
Public companion functions
startInitialization
fun startInitialization(context: Context): PdfSandboxHandle
Prepares sandboxing PDF resources ahead of any document operations, to reduce latency during the interaction with the SandboxedPdfLoader or PdfDocument.
The returned PdfSandboxHandle represents a session and must be closed by the caller when no longer needed.
Calling this method is optional. Any document operation via SandboxedPdfLoader and PdfDocument will initialize the resources internally on demand, but may experience increased startup time.
| Returns | |
|---|---|
PdfSandboxHandle |
A |
| See also | |
|---|---|
PdfSandboxHandle |
Public constructors
SandboxedPdfLoader
SandboxedPdfLoader(
context: Context,
coroutineContext: CoroutineContext = EmptyCoroutineContext
)
Creates a new SandboxedPdfLoader instance.
| Parameters | |
|---|---|
context: Context |
The |
coroutineContext: CoroutineContext = EmptyCoroutineContext |
The
|
Public functions
openDocument
open 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 |
| Throws | |
|---|---|
PdfPasswordException |
If the provided password is incorrect. |
IOException |
If an error occurs while opening the document. |
openDocument
open suspend fun openDocument(
uri: Uri,
fileDescriptor: ParcelFileDescriptor,
password: String? = null,
renderParams: RenderParams = RenderParams(renderMode = RenderParams.RENDER_MODE_FOR_DISPLAY)
): 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 |
fileDescriptor: ParcelFileDescriptor |
a |
password: String? = null |
(Optional) The password to unlock the document if it is encrypted. |
renderParams: 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 |
| Returns | |
|---|---|
PdfDocument |
The opened |
| Throws | |
|---|---|
PdfPasswordException |
If the provided password is incorrect. |
IOException |
If an error occurs while opening the document. |