KiteDocView

fun KiteDocView(state: KiteDocViewState, modifier: Modifier = Modifier, layout: KiteDocLayout = KiteDocLayout.Default, zoomSpec: KiteZoomSpec = KiteZoomSpec(), renderSpec: KiteRenderSpec = KiteRenderSpec.Default, colors: KiteDocViewColors = KiteDocViewColors(), pageSpacing: Dp = 8.dp, userScrollEnabled: Boolean = true, selectionEnabled: Boolean = true, onPageRendered: (pageIndex: Int, image: ImageBitmap) -> Unit? = null, pagePlaceholder: @Composable (pageIndex: Int) -> Unit? = null, chapterPlaceholder: @Composable (chapter: Int) -> Unit? = null, overlay: @Composable BoxScope.(KiteDocViewState) -> Unit? = null, onTap: (Offset) -> Unit? = null, onLinkTap: (KiteLinkAction) -> Boolean? = null, scripts: PdfScriptHandler? = null, onHighlightTap: (KiteHighlight) -> Boolean? = null, onEpubReferenceTap: (EpubLink) -> Boolean? = null)

THE KitePDF viewer composable. It draws a KiteDocument, so a PDF and an EPUB go through the same code path, the same gestures and the same widgets.

// Simple: whole document, vertical continuous scroll.
KiteDocView(rememberKiteDocViewState(doc), Modifier.fillMaxSize())

// Full control: horizontal pager, custom zoom, HUD overlay.
val state = rememberKiteDocViewState(doc)
KiteDocView(
state = state,
layout = KiteDocLayout.Paged(Orientation.Horizontal),
zoomSpec = KiteZoomSpec(maxZoom = 6f),
overlay = { s ->
KiteNavigationControls(s, Modifier.align(Alignment.BottomCenter))
},
)
// …and the same state drives widgets OUTSIDE the viewport too:
KitePageIndicator(state)

By default (KiteRenderSpec.Rasterized) pages are vector-rendered once into an ImageBitmap per (page, size, zoom bucket) and then drawn as plain images, so scrolling, panning and pinching never redraw the page itself. Switch to KiteRenderSpec.Vectorized for resolution-independent, bitmap-free drawing. See KiteRenderSpec for the per-mode knobs and KiteZoomSpec for gestures.

Parameters

state

the hoisted control surface. See rememberKiteDocViewState.

layout

continuous strip (any orientation), snap pager (any orientation) or a single fixed page. See KiteDocLayout.

zoomSpec

pinch/double-tap/pan behaviour and zoom bounds. Programmatic zoom through KiteDocViewState.setZoom honours the same bounds, so external controls (sliders, loupes) work with gestures fully disabled.

renderSpec

how pages become pixels: KiteRenderSpec.Rasterized (bitmap-cached, with quality/memory/crisp-zoom/hairline knobs) or KiteRenderSpec.Vectorized (live vector draw). See KiteRenderSpec.

colors

page paper + viewport letterbox colours.

pageSpacing

gap between pages (continuous gutter / pager spacing).

selectionEnabled

whether the reader may select text at all. The default, true, is the long-press-to-select behaviour with draggable thumbs. False removes the gesture entirely: no long press selects, no wash is painted, no thumbs appear, and a selection already on screen is dropped. Turn it off for a document shown as a picture, a chart, a scan, a trace, where a text selection means nothing and a stray long press only gets in the way of panning.

userScrollEnabled

gesture scrolling/swiping of the layout itself. Disable to drive paging exclusively through KiteDocViewState (nav buttons).

onPageRendered

fires whenever a page finishes a FRESH rasterization, with the bitmap ready for export, e.g. via encodeToPng. Cache hits from the page-bitmap LRU do not re-fire it.

pagePlaceholder

shown in a page's slot until its raster is ready. Defaults to a plain KiteDocViewColors.pageBackground box.

chapterPlaceholder

shown in the slot a chapter holds while it is still being laid out. Only reflowable EPUB reaches this: a PDF is never mid-layout. Defaults to an empty page-coloured box.

overlay

HUD layer drawn over the viewport; receives state and a BoxScope for alignment. Widgets here float above the pages: KiteNavigationControls, KitePageIndicator, KiteThumbnailStrip or anything of your own.

onTap

single-tap on the page, reported with the tap position. The tap does not consume pan/swipe, so it coexists with navigation. Typical use is toggling a HUD's visibility. Held back until the double-tap window lapses only when KiteZoomSpec.doubleTapEnabled is on. Taps that land on a link navigate (or go to onLinkTap) instead of reaching this callback.

onLinkTap

fires when a tapped link carries something the viewer can't perform itself: a URL, a remote GoTo, a Launch. Return true after handling it (e.g. opening the URL in a browser); false lets the tap fall through to onTap. Internal go-to-page links (PDF destinations, EPUB internal hrefs) never reach this: the viewer scrolls to the target page directly. An EPUB reference to a note goes to onEpubReferenceTap first. See KiteLinkAction for the payload; link.uri covers both formats.


fun KiteDocView(document: KiteDocument, modifier: Modifier = Modifier, page: Int? = null, background: Color = Color.White, theme: ReaderTheme? = null, pageSpacing: Dp = 8.dp, selectionEnabled: Boolean = true, onPageRendered: (pageIndex: Int, image: ImageBitmap) -> Unit? = null, onTap: (Offset) -> Unit? = null, onLinkTap: (KiteLinkAction) -> Boolean? = null)

Convenience entry point: remembers its own state internally. Takes any KiteDocument, so a PdfDocument and an io.github.yuroyami.kitepdf.epub.EpubDocument both go here.

KiteDocView(document = doc, modifier = Modifier.fillMaxSize())          // whole document
KiteDocView(document = doc, page = 0, modifier = Modifier.fillMaxWidth()) // one page

Parameters

page

index of the single page to show, or null (default) for the whole document as a continuous vertical scroll.

background

colour painted behind page content. Ignored when theme is set (the theme owns the paper colour).

theme

optional reading theme: ReaderTheme.Dark for night mode, ReaderTheme.Sepia, or ReaderTheme.Light/null for the author's colours. Applied at render, so switching is instant (no re-layout).

selectionEnabled

whether the reader may select text. See the state-based KiteDocView for what turning it off removes.