PdfView

fun PdfView(state: PdfViewState, modifier: Modifier = Modifier, layout: PdfLayout = PdfLayout.Default, zoomSpec: PdfZoomSpec = PdfZoomSpec(), renderSpec: PdfRenderSpec = PdfRenderSpec.Default, colors: PdfViewColors = PdfViewColors(), pageSpacing: Dp = 8.dp, userScrollEnabled: Boolean = true, onPageRendered: (pageIndex: Int, image: ImageBitmap) -> Unit? = null, pagePlaceholder: @Composable (pageIndex: Int) -> Unit? = null, overlay: @Composable BoxScope.(PdfViewState) -> Unit? = null, onTap: (Offset) -> Unit? = null, onLinkTap: (PdfAction) -> Boolean? = null)

THE KitePDF viewer composable.

// Simple: whole document, vertical continuous scroll.
PdfView(rememberPdfViewState(doc), Modifier.fillMaxSize())

// Full control: horizontal pager, custom zoom, HUD overlay.
val state = rememberPdfViewState(doc)
PdfView(
state = state,
layout = PdfLayout.Paged(Orientation.Horizontal),
zoomSpec = PdfZoomSpec(maxZoom = 6f),
overlay = { s ->
PdfNavigationControls(s, Modifier.align(Alignment.BottomCenter))
},
)
// …and the same state drives widgets OUTSIDE the viewport too:
PdfPageIndicator(state)

By default (PdfRenderSpec.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 re-execute the PDF content stream. Switch to PdfRenderSpec.Vectorized for resolution-independent, bitmap-free drawing. See PdfRenderSpec for the per-mode knobs and PdfZoomSpec for gestures.

Parameters

state

the hoisted control surface. See rememberPdfViewState.

layout

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

zoomSpec

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

renderSpec

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

colors

page paper + viewport letterbox colours.

pageSpacing

gap between pages (continuous gutter / pager spacing).

userScrollEnabled

gesture scrolling/swiping of the layout itself. Disable to drive paging exclusively through PdfViewState (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 T-15 bitmap LRU do not re-fire it.

pagePlaceholder

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

overlay

HUD layer drawn over the viewport; receives state and a BoxScope for alignment. Widgets here float above the pages: PdfNavigationControls, PdfPageIndicator, PdfThumbnailStrip 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 PdfZoomSpec.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 an action the viewer can't perform itself: a URI, 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.


fun PdfView(document: PdfDocument, modifier: Modifier = Modifier, page: Int? = null, background: Color = Color.White, pageSpacing: Dp = 8.dp, onPageRendered: (pageIndex: Int, image: ImageBitmap) -> Unit? = null, onTap: (Offset) -> Unit? = null, onLinkTap: (PdfAction) -> Boolean? = null)

Convenience entry point: remembers its own state internally.

PdfView(document = doc, modifier = Modifier.fillMaxSize())          // whole document
PdfView(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.