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.

KPDF is a Kotlin Multiplatform PDF library that brings a full-featured PDF viewer to Android and iOS Compose Multiplatform apps. You add two Gradle dependencies, point the SDK at a PDF source, and get rendering, caching, zoom, swipe navigation, save/export, and connected toolbar and thumbnail views — all driven by a single KPdfViewerState.

Two modules, one viewer

KPDF ships as two independent modules that work together:
  • kpdf-core — The shared PDF engine. Handles source loading, page rendering, RAM and disk caching, navigation, zoom, save/export, external-open, and device file picker state. This is the module you depend on from non-UI code.
  • kpdf-compose — Compose Multiplatform UI components and platform integrations. Provides KPdfViewer, KPdfViewerToolbar, KPdfThumbnailStrip, and rememberPdfViewerState, as well as the platform-specific save and open flow bindings for Android and iOS.
Most apps add both modules. kpdf-core alone is enough if you only need the engine APIs — for example, to render pages to bitmaps outside a Compose surface.

Supported platforms

KPDF targets Android and iOS via Kotlin Multiplatform. You write your viewer screen once in shared Compose Multiplatform code and it runs on both platforms.

PDF sources

Tell KPDF where your PDF comes from by creating a KPdfSource:
  • KPdfSource.Url — Loads a PDF over HTTPS. Accepts custom request headers for authenticated endpoints.
  • KPdfSource.Bytes — Takes a ByteArray you have already loaded.
  • KPdfSource.Base64 — Accepts a raw Base64 string or a data:application/pdf;base64,... data URL.
// Remote PDF with an auth header
val urlSource = KPdfSource.Url(
    url = "https://example.com/document.pdf",
    headers = mapOf("Authorization" to "Bearer token")
)

// Bytes you loaded yourself
val bytesSource = KPdfSource.Bytes(pdfBytes)

// Base64-encoded content
val base64Source = KPdfSource.Base64(base64String)

Key features

Quick start

Display your first PDF in under five minutes with a minimal end-to-end working example.

Installation

Add kpdf-core and kpdf-compose to your Gradle build and get up and running.

PDF sources

Load from HTTPS URLs with custom headers, raw byte arrays, or Base64 strings including data URLs.

Viewer state

Control navigation, zoom, save, export, and device file picking through a single KPdfViewerState.

What the SDK handles for you

  • RAM and disk page caching — Configurable cache sizes keep scrolling smooth and allow offline reopening of previously loaded remote documents.
  • Configurable preloading — The viewer renders nearby pages in the background so swiping feels instant.
  • Zoom — Pinch-to-zoom and double-tap zoom with a configurable zoom range and double-tap zoom level.
  • Save and exportrequestSave() launches the platform file picker. exportPdf() returns raw bytes for custom share flows.
  • Open from devicerequestOpenFromDevice() triggers the platform document picker and returns the selected file as a new KPdfSource.
  • Open in external appopenInExternalApp() hands the current PDF to any installed app that can open PDFs.
  • Connected viewsKPdfViewerToolbar and KPdfThumbnailStrip share the same KPdfViewerState as the main viewer with no extra wiring.