Skip to main content
KPdfSource is the sealed interface that tells KPDF where to find a PDF document. Every viewer instance is backed by exactly one source, and the SDK treats distinct source values as distinct documents. Choose the variant that matches how your app obtains the PDF — a remote URL, an already-decoded byte array, or an inline Base64 string — and pass it to rememberPdfViewerState or KPdfViewerState.open.

The three source variants

Use KPdfSource.Url when the document lives at a network address. Pass custom headers to authenticate the request or negotiate the response format. KPDF treats headers as part of the source identity: two Url instances with the same URL but different headers are considered different sources, so the viewer reloads when headers change.
Use KPdfSource.Bytes when your app already has the PDF content in memory — for example, after downloading it yourself, generating it programmatically, or reading it from a local file. Hand the ByteArray directly to KPDF; the SDK does not perform any network requests.
KPdfSource.Bytes implements equals and hashCode using contentEquals / contentHashCode on the underlying array, so two Bytes instances wrapping identical content compare as equal.
Use KPdfSource.Base64 when the PDF arrives as a Base64-encoded string, such as from a JSON API response or an embedded asset. Pass either a raw Base64 string or a complete data URL — KPDF handles both formats.

Passing a source to the viewer

To switch the active document at runtime, call viewerState.open(newSource). KPDF cancels any in-flight work and starts loading the new source immediately.
Wrap your KPdfSource in remember (or hoist it to a ViewModel) so that Compose recompositions do not create a new source object on every frame. If the source reference changes, rememberPdfViewerState treats it as a new document and restarts the load pipeline.