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 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:
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:
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 guide:
@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),
        )
    }
}
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.