This guide walks you through the shortest path to a working PDF viewer. By the end you will have a composable that loads a PDF from any source, renders pages with pinch-to-zoom and swipe navigation, and handles its own lifecycle cleanup.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.
Add the dependencies
Add both KPDF modules to your shared module’s
build.gradle.kts:kpdf-core provides the PDF engine and state APIs. kpdf-compose provides the Compose viewer components and the platform save/open integrations. You need both for a full viewer.See Installation for full Gradle setup details and Groovy DSL equivalents.Create a KPdfSource
Create a For authenticated remote PDFs, pass request headers:
KPdfSource that tells the SDK where your PDF comes from. KPDF supports URLs, raw bytes, and Base64 strings:Call rememberPdfViewerState
Inside your composable, call
rememberPdfViewerState to create and remember the viewer state. Wrap source in remember and build KPdfViewerConfig inside remember so neither is reconstructed on every recomposition:Keep
source and config stable with remember. If you rebuild KPdfViewerConfig inline on every recomposition, rememberPdfViewerState recreates the viewer state and transient flows such as openDocumentState reset back to Idle.Complete minimal example
Here is the full composable from the steps above assembled together:KPdfSource to PdfScreen and the viewer handles loading, rendering, caching, and cleanup when the composable leaves the composition.
Next steps
Once the basic viewer is working, you can extend it with connected views and platform flows:- Add
KPdfViewerToolbarandKPdfThumbnailStripusing the sameviewerState— no extra wiring required. - Call
viewerState.requestSave()to let users save the current PDF to their device. - Call
viewerState.requestOpenFromDevice()to let users pick a local PDF. - Call
viewerState.openInExternalApp()to hand the PDF to another installed app. - Use
viewerState.exportPdf()to get raw bytes and feed them into your own share flow.