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.
KPdfViewerState is the main interface you interact with after creating a viewer. It exposes the document’s loading and rendering state through StateFlow properties, and provides methods to navigate pages, control zoom, open files from the device, save the document, hand it off to an external app, render individual pages off-screen, and release resources. One KPdfViewerState instance maps to one visible viewer; share the same instance across KPdfViewer, KPdfThumbnailStrip, and KPdfViewerToolbar so they stay in sync.
In Compose, obtain an instance through rememberPdfViewerState. For non-Compose contexts, use KPdfFactory.
Observable properties
These properties expose the current state of the viewer. Collect them withcollectAsState() in Compose or with collect {} in a coroutine scope outside Compose.
The source that is currently loaded or being loaded. Updated synchronously when you call
open(source).The viewer configuration that was provided when this state was created. Immutable for the lifetime of the state instance.
Tracks the overall document loading lifecycle. Observe this to show loading indicators and handle errors.
The 0-based index of the page currently displayed in the viewer.
The active zoom level as a
Float. The range is determined by the minZoom and maxZoom values in KPdfViewerConfig.The rendering state of the currently active page surface. Use this to react to render completion or render failures.
Tracks the state of a device-picker open request initiated by
requestOpenFromDevice(). Progresses through Idle, AwaitingSelection, Success, Cancelled, and Error. See KPdfOpenDocumentState.Tracks the state of a save request initiated by
requestSave() or savePdf(). Progresses through Idle, Exporting, AwaitingDestination, Success, Cancelled, and Error. See KPdfSaveState.Tracks the state of an external-app open request initiated by
requestOpenInExternalApp() or openInExternalApp(). Progresses through Idle, Exporting, AwaitingExternalApp, Success, Cancelled, and Error. See KPdfExternalOpenState.Methods
open
Opens a PDF source, cancelling any in-flight load or render work owned by this state instance.The source to open. Defaults to the source already held by this state, which means calling
open() with no arguments reloads the current document.retry
Retries the most recentopen request. Call this when loadState reports a failure and you want to give the user a way to try again without changing the source.
nextPage
Advances the viewer to the next page. Has no effect when the last page is already displayed.previousPage
Moves the viewer back to the immediately preceding page. Has no effect when the first page is already displayed.goToPage
Navigates directly to a specific page by its 0-based index.The 0-based index of the target page. Page 1 of the document is index
0.setZoom
Sets the zoom level for the active page surface to an exact value.The target zoom level. Should be within the
minZoom–maxZoom range defined in KPdfViewerConfig; values outside the range are coerced.zoomIn
Increases the current zoom by one viewer-defined step.zoomOut
Decreases the current zoom by one viewer-defined step.resetZoom
Resets the zoom back to the configured minimum zoom level.requestOpenFromDevice
Triggers the platform’s native document picker so the user can select a PDF from local storage. When the user completes the picker flow,openDocumentState transitions to Success with the selected source. Call open(selectedSource) to load it.
The MIME types accepted by the platform picker. Defaults to PDF only.
requestSave
Requests that the SDK export the current PDF and trigger the platform’s save/destination picker. ObservesaveState to react to the outcome.
The file name pre-filled in the platform save dialog. Pass
null to let the platform decide.The MIME type used when writing the file. Defaults to
application/pdf.savePdf
Alias forrequestSave. Accepts the same parameters and delegates directly to it. Prefer whichever name reads more clearly at your call site.
The file name pre-filled in the platform save dialog.
The MIME type used when writing the file.
requestOpenInExternalApp
Requests that the SDK export the current PDF and hand it to an installed app that can open PDF content (e.g., a system PDF viewer). ObserveexternalOpenState to react to the outcome.
The file name suggested to the receiving app or OS share sheet.
The MIME type used when handing off the file. Defaults to
application/pdf.openInExternalApp
Alias forrequestOpenInExternalApp. Accepts the same parameters and delegates directly to it.
The file name suggested to the receiving app or OS share sheet.
The MIME type used when handing off the file.
renderPage
Renders a specific page to an off-screen bitmap. This is asuspend function; call it from a coroutine scope. Use it when you need pixel-level access to a page — for example, to feed a custom sharing flow — rather than to display it in the viewer.
The 0-based index of the page to render.
The desired width of the output bitmap in pixels.
The desired height of the output bitmap in pixels.
The zoom factor to apply when rendering. Defaults to
1f (no zoom).Result<KPdfPageBitmap>. Check isSuccess before using the value.
exportPdf
Exports the currently configured PDF source as raw bytes. This is asuspend function. Use the returned bytes to implement a custom share flow that bypasses the SDK’s built-in save/external-open paths.
Returns Result<ByteArray>.