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.

KPdfFactory is the entry point to the KPDF SDK outside of Compose. It exposes a single static method, create(), that returns a KPdf facade. From the facade you call viewerState() to produce a KPdfViewerState — the same interface used internally by rememberPdfViewerState. Use this path when you need to manage viewer state in a ViewModel, a non-Compose screen, or any other context where Compose lifecycle hooks are not available.
If you are building a Compose Multiplatform UI, prefer rememberPdfViewerState from the kpdf-compose module. It wires up the platform save, open, and external-app effects automatically and ties the viewer state lifetime to the composition. Use KPdfFactory only when you have a concrete reason to manage the lifecycle yourself.

KPdfFactory.create

Returns a platform-specific implementation of the KPdf facade. KPdfFactory is an expect object, so the actual implementation is resolved per platform at compile time.
fun create(): KPdf

KPdf.viewerState

Creates a KPdfViewerState for the given source and configuration. You own the state’s lifetime — call close() when the viewer is no longer needed to release cached pages and coroutine work.
source
KPdfSource
required
The PDF source to load. See KPdfSource for the available variants.
config
KPdfViewerConfig
default:"KPdfViewerConfig.builder().build()"
The viewer configuration. Defaults to a config with all options at their default values. See KPdfViewerConfig for the full list of options.
Returns KPdfViewerState.

Usage

// 1. Create the SDK facade (once, e.g. in a ViewModel or DI graph)
val sdk = KPdfFactory.create()

// 2. Create a viewer state for a specific source
val viewerState = sdk.viewerState(
    source = KPdfSource.Url("https://example.com/document.pdf"),
    config = KPdfViewerConfig.builder()
        .zoomRange(minZoom = 1f, maxZoom = 4f)
        .preloadPageCount(1)
        .build(),
)

// 3. Use the state, then release it when done
viewerState.close()