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

# Share a PDF using exportPdf and your platform share flow

> Call exportPdf to get the current PDF as a ByteArray, then pass the bytes to your own Android or iOS share mechanism — KPDF does not impose a share UI.

KPDF deliberately does not own the share UI. Instead, `exportPdf()` returns the current PDF as a `Result<ByteArray>`. You take those bytes and pass them to your own Android Intent or iOS `UIActivityViewController`. This keeps platform share behaviour fully under your control.

## Coroutine-based share example

`exportPdf()` is a suspending function, so launch it from a `CoroutineScope`. Use `fold` to handle success and failure in one expression:

```kotlin theme={null}
val scope = rememberCoroutineScope()

Button(
    onClick = {
        scope.launch {
            viewerState.exportPdf().fold(
                onSuccess = { pdfBytes ->
                    sharePdfBytes(pdfBytes)  // your platform share implementation
                },
                onFailure = { error ->
                    println("Export failed: ${error.message}")
                },
            )
        }
    }
) {
    Text("Share")
}
```

## Using onSuccess / onFailure separately

If you prefer to handle each branch independently, use `onSuccess` and `onFailure`:

```kotlin theme={null}
scope.launch {
    viewerState.exportPdf()
        .onSuccess { pdfBytes ->
            sharePdfBytes(pdfBytes)
        }
        .onFailure { error ->
            showErrorSnackbar(error.message)
        }
}
```

## Full integration example

The snippet below shows the share flow wired into a `KPdfViewerToolbar`, matching the full-screen example from the [Display a PDF](/guides/display-pdf) guide:

```kotlin theme={null}
@Composable
fun PdfScreenWithShare(source: KPdfSource) {
    val viewerState = rememberPdfViewerState(source = source)
    val scope = rememberCoroutineScope()
    var thumbnailsVisible by remember { mutableStateOf(true) }

    Column(modifier = Modifier.fillMaxSize()) {
        KPdfViewerToolbar(
            state = viewerState,
            isThumbnailStripVisible = thumbnailsVisible,
            onThumbnailToggle = { thumbnailsVisible = it },
            onShareClick = {
                scope.launch {
                    viewerState.exportPdf().onSuccess { bytes ->
                        sharePdfBytes(bytes)
                    }
                }
            },
            modifier = Modifier
                .fillMaxWidth()
                .padding(12.dp),
        )

        KPdfViewer(
            state = viewerState,
            modifier = Modifier
                .fillMaxWidth()
                .weight(1f),
        )
    }
}
```

<Note>
  KPDF intentionally does not show a share sheet or system dialog. After `exportPdf()` resolves, your app is responsible for passing the `ByteArray` to the appropriate platform API — `Intent.ACTION_SEND` on Android or `UIActivityViewController` on iOS. This gives you full control over the share target, the MIME type, and any additional metadata.
</Note>
