> ## Documentation Index
> Fetch the complete documentation index at: https://mahmoud-b28887f9.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Open the current PDF in an installed PDF viewer app

> Call openInExternalApp or requestOpenInExternalApp to hand the current PDF to another app, then observe KPdfExternalOpenState for success or failure.

KPDF can hand the current PDF off to any installed app that handles PDF content — for example, Adobe Acrobat or the system Files app. Call `openInExternalApp()` to start the flow. The SDK exports the file and triggers the platform's app-chooser or sends it directly to the default PDF handler. Observe `externalOpenState` if you want to react to success or failure.

## Basic usage

```kotlin theme={null}
Button(onClick = { viewerState.openInExternalApp() }) {
    Text("Open in external app")
}
```

`openInExternalApp()` is an alias for `requestOpenInExternalApp()`. Both accept the same parameters — use whichever reads more clearly at your call site.

## Suggesting a file name

Pass a `suggestedFileName` to control the name the receiving app sees:

```kotlin theme={null}
Button(onClick = {
    viewerState.requestOpenInExternalApp(
        suggestedFileName = "report-q1.pdf",
    )
}) {
    Text("Open report in external app")
}
```

## Observing state

Collect `externalOpenState` to keep your UI in sync with the flow:

```kotlin theme={null}
val externalOpenState by viewerState.externalOpenState.collectAsState()
```

## Full pattern with state observation

```kotlin theme={null}
@Composable
fun ExternalAppExample(viewerState: KPdfViewerState) {
    val externalOpenState by viewerState.externalOpenState.collectAsState()

    Button(onClick = {
        viewerState.requestOpenInExternalApp(suggestedFileName = "document.pdf")
    }) {
        Text("Open in external app")
    }

    when (val state = externalOpenState) {
        KPdfExternalOpenState.Idle -> Unit
        KPdfExternalOpenState.Exporting -> {
            Text("Preparing PDF…")
        }
        is KPdfExternalOpenState.AwaitingExternalApp -> {
            Text("Launching external app…")
        }
        is KPdfExternalOpenState.Success -> {
            Text("Opened successfully.")
        }
        is KPdfExternalOpenState.Cancelled -> {
            Text("Cancelled.")
        }
        is KPdfExternalOpenState.Error -> {
            Text("Could not open external app: ${state.reason}")
        }
    }
}
```

## KPdfExternalOpenState variants

| State                 | When it occurs                   | What it carries                                           | Suggested UI reaction        |
| --------------------- | -------------------------------- | --------------------------------------------------------- | ---------------------------- |
| `Idle`                | No open in progress              | —                                                         | No indicator                 |
| `Exporting`           | SDK is serialising the PDF bytes | —                                                         | Show a progress indicator    |
| `AwaitingExternalApp` | Platform app chooser is open     | `requestId`, `suggestedFileName`, `mimeType`              | Tell the user to pick an app |
| `Success`             | External app received the file   | `requestId`, `suggestedFileName`, `mimeType`, `location?` | Dismiss the indicator        |
| `Cancelled`           | User dismissed the app chooser   | `requestId`, `suggestedFileName`, `mimeType`              | Restore previous UI silently |
| `Error`               | Export or handoff failed         | `reason`, `suggestedFileName?`, `mimeType?`               | Show an error message        |

<Warning>
  If no PDF viewer is installed on the device, the platform will report an error. Handle `KPdfExternalOpenState.Error` and show a message that guides the user to install a PDF app.
</Warning>
