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’s save flow exports the current PDF and opens the platform’s save-file picker so the user can choose where to store it. Call requestSave() (or the alias savePdf()) to start the flow. The SDK writes the file once the user selects a destination. Observe saveState to update your UI throughout the process.

Basic save

@Composable
fun SaveExample(viewerState: KPdfViewerState) {
    val saveState by viewerState.saveState.collectAsState()

    Button(onClick = { viewerState.requestSave() }) {
        Text("Save PDF")
    }

    when (saveState) {
        KPdfSaveState.Idle -> Unit
        KPdfSaveState.Exporting -> Text("Preparing PDF…")
        is KPdfSaveState.AwaitingDestination -> Text("Choose where to save the file.")
        is KPdfSaveState.Success -> Text("PDF saved successfully.")
        is KPdfSaveState.Cancelled -> Text("Save cancelled.")
        is KPdfSaveState.Error -> Text("Save failed: ${saveState.reason}")
    }
}

Suggesting a file name

Pass a suggestedFileName to pre-fill the file name in the platform picker:
Button(onClick = {
    viewerState.requestSave(suggestedFileName = "invoice-2026.pdf")
}) {
    Text("Save as invoice")
}
savePdf() is an alias for requestSave() with the same parameters — use whichever reads more clearly at your call site.

KPdfSaveState variants

saveState is a StateFlow<KPdfSaveState>. Handle each variant to give users accurate feedback.
StateWhen it occursWhat it carriesSuggested UI reaction
IdleNo save in progressNo indicator
ExportingSDK is serialising the PDF bytesShow a progress indicator
AwaitingDestinationPlatform save picker is openrequestId, suggestedFileName, mimeTypeTell the user to pick a save location
SuccessFile written successfullyrequestId, suggestedFileName, mimeType, location?Show a confirmation, optionally surface the save path
CancelledUser dismissed the pickerrequestId, suggestedFileName, mimeTypeDismiss the indicator silently
ErrorExport or write failedreason, suggestedFileName?, mimeType?Show an error message with the failure reason
when (val state = saveState) {
    KPdfSaveState.Idle -> Unit
    KPdfSaveState.Exporting -> {
        LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
    }
    is KPdfSaveState.AwaitingDestination -> {
        Text("Waiting for you to pick a location…")
    }
    is KPdfSaveState.Success -> {
        Text("Saved to ${state.location ?: "device storage"}.")
    }
    is KPdfSaveState.Cancelled -> {
        Text("Save cancelled.")
    }
    is KPdfSaveState.Error -> {
        Text("Could not save: ${state.reason}")
    }
}
Use requestSave when you want the SDK to manage the full save-picker flow. If you need to share the raw bytes with your own share sheet or upload logic, use exportPdf() instead — see Share a PDF.