ComposePdfViewer
ComposePdfViewer copied to clipboard
A simple PDF Viewer for Jetpack Compose
ComposePdfViewer
A simple Jetpack Compose PDF viewer
Demo

Usage
PdfViewer(
pdfResId = R.raw.demo,
modifier = Modifier.fillMaxSize(),
backgroundColor = Color(0xFF909090),
pageColor = Color.White,
listDirection = PdfListDirection.VERTICAL,
arrangement = Arrangement.spacedBy(16.dp),
fallbackWidget = {
Icon(
Icons.Rounded.Info,
contentDescription = "Error Component"
)
},
loadingListener = { isLoading, currentPage, maxPage ->
// Observe loading changes
}
)
// Or if you already have an InputStream
PdfViewer(
pdfStream = inputStream,
modifier = Modifier.fillMaxSize(),
backgroundColor = Color(0xFF909090),
pageColor = Color.White,
listDirection = PdfListDirection.VERTICAL,
arrangement = Arrangement.spacedBy(16.dp),
fallbackWidget = {
// Display Custom Widget if an error occurred while rendering the pdf file
},
loadingListener = { isLoading, currentPage, maxPage ->
// Observe loading changes
}
)
// Or if you want to implement your own page layout
PdfViewer(
pdfStream = inputStream,
modifier = Modifier.fillMaxSize(),
backgroundColor = Color(0xFF909090),
listDirection = PdfListDirection.VERTICAL,
arrangement = Arrangement.spacedBy(16.dp),
fallbackWidget = {
// Display Custom Widget if an error occurred while rendering the pdf file
},
loadingListener = { isLoading, currentPage, maxPage ->
// Observe loading changes
},
page = { lazyListState, imageBitmap ->
// Implement your own custom page
}
)
Known problems
- Zoom pan is not restricted (Any fix to that should go to ComposeZoomableImagePlus)
- Load performance is slow (on average, the PDF Viewer loads about 4 pages a second on a Pixel 2 emulator)
Future changes (other than fixing the known problems)
- Add ram caching for the pdf pages in case the PDF is not as heavy and doesn't need disk caching
- Publish to Jitpack