Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mahmoud-b28887f9.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

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

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:
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:
val externalOpenState by viewerState.externalOpenState.collectAsState()

Full pattern with state observation

@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

StateWhen it occursWhat it carriesSuggested UI reaction
IdleNo open in progressNo indicator
ExportingSDK is serialising the PDF bytesShow a progress indicator
AwaitingExternalAppPlatform app chooser is openrequestId, suggestedFileName, mimeTypeTell the user to pick an app
SuccessExternal app received the filerequestId, suggestedFileName, mimeType, location?Dismiss the indicator
CancelledUser dismissed the app chooserrequestId, suggestedFileName, mimeTypeRestore previous UI silently
ErrorExport or handoff failedreason, suggestedFileName?, mimeType?Show an error message
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.