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

# KPdfFactory: create a KPDF viewer state outside Compose

> KPdfFactory.create() returns a KPdf facade for creating KPdfViewerState instances outside Compose — useful in ViewModels or non-Compose contexts.

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

<Note>
  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.
</Note>

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

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

<ParamField path="source" type="KPdfSource" required>
  The PDF source to load. See [`KPdfSource`](/api/kpdf-source) for the available variants.
</ParamField>

<ParamField path="config" type="KPdfViewerConfig" default="KPdfViewerConfig.builder().build()">
  The viewer configuration. Defaults to a config with all options at their default values. See [`KPdfViewerConfig`](/api/kpdf-viewer-config) for the full list of options.
</ParamField>

Returns `KPdfViewerState`.

## Usage

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