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

# Save or export the active PDF to the user's device

> Call requestSave to trigger the platform save picker, observe KPdfSaveState for every stage of the flow, and handle Success, Cancelled, and Error outcomes.

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

```kotlin theme={null}
@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:

```kotlin theme={null}
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.

| State                 | When it occurs                   | What it carries                                           | Suggested UI reaction                                 |
| --------------------- | -------------------------------- | --------------------------------------------------------- | ----------------------------------------------------- |
| `Idle`                | No save in progress              | —                                                         | No indicator                                          |
| `Exporting`           | SDK is serialising the PDF bytes | —                                                         | Show a progress indicator                             |
| `AwaitingDestination` | Platform save picker is open     | `requestId`, `suggestedFileName`, `mimeType`              | Tell the user to pick a save location                 |
| `Success`             | File written successfully        | `requestId`, `suggestedFileName`, `mimeType`, `location?` | Show a confirmation, optionally surface the save path |
| `Cancelled`           | User dismissed the picker        | `requestId`, `suggestedFileName`, `mimeType`              | Dismiss the indicator silently                        |
| `Error`               | Export or write failed           | `reason`, `suggestedFileName?`, `mimeType?`               | Show an error message with the failure reason         |

```kotlin theme={null}
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}")
    }
}
```

<Tip>
  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](/guides/share-pdf).
</Tip>
