
Read, render and display PDF documents with PDFium-backed core; exposes metadata, rendering, text and search. Scrolling Compose viewer adds zoom, link handling and highlightable search results.
| Library | English | 简体中文 |
|---|---|---|
pdf-core |
Using PDF Core | PDF Core 使用指南 |
pdf-viewer |
Using PDF Viewer | PDF Viewer 使用指南 |
PDF Viewer KMP is a PDFium-backed Kotlin Multiplatform library for reading, rendering, and displaying PDF documents.
Download the signed Android demo: pdf-viewer-kmp-demo.apk.
The project is split into two public libraries:
| Library | Purpose |
|---|---|
pdf-core |
Opens PDF documents and exposes metadata, page rendering, text, search, and links without requiring Compose UI. |
pdf-viewer |
Provides the PdfView Compose Multiplatform component with zoom, links, search state, and configurable result highlighting. It depends on pdf-core transitively. |
| Platform | Supported targets |
|---|---|
| Android | arm32, arm64, x86, x64 |
| iOS | device arm64, simulator arm64 |
| JVM desktop | macOS arm64/x64, Linux x64, Windows x64 |
| Browser | JavaScript, Wasm |
iOS x64 and Catalyst are not currently supported. The bundled PDFium build is
pinned to chromium/7961 and does not include V8 or XFA.
Add Maven Central and choose the library needed by commonMain:
repositories {
mavenCentral()
}
kotlin {
sourceSets {
commonMain.dependencies {
// PDF APIs only:
implementation("io.github.limuyang2:pdf-core:0.2.2")
// Or the Compose viewer. pdf-core is included transitively:
implementation("io.github.limuyang2:pdf-viewer:0.2.2")
}
}
}Use pdf-core when the application needs to inspect or render PDFs without the
built-in Compose UI:
import io.github.limuyang2.pdf.core.PdfPixelSize
import io.github.limuyang2.pdf.core.PdfRenderRequest
import io.github.limuyang2.pdf.core.PdfSource
import io.github.limuyang2.pdf.core.PdfViewer
suspend fun renderFirstPage(pdfBytes: ByteArray): ByteArray {
val document = PdfViewer.open(PdfSource.Bytes(pdfBytes))
try {
require(document.pageCount > 0)
val bitmap =
document[0].render(
PdfRenderRequest(
outputSize = PdfPixelSize(1200, 1600),
),
)
try {
return bitmap.copyPixels()
} finally {
bitmap.close()
}
} finally {
document.close()
}
}See Using PDF Core for passwords, metadata, text, search, links, bitmap formats, resource ownership, exceptions, and platform-specific setup.
pdf-viewer displays every page in a vertically scrolling Compose view:
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import io.github.limuyang2.pdf.core.PdfDocument
import io.github.limuyang2.pdf.viewer.PdfView
import io.github.limuyang2.pdf.viewer.rememberPdfViewState
@Composable
fun DocumentPreview(document: PdfDocument) {
val state = rememberPdfViewState()
PdfView(
document = document,
state = state,
modifier = Modifier.fillMaxSize(),
maxZoom = 4f,
gestureZoomEnabled = true,
)
}The caller owns PdfDocument and must close it when the screen is disposed.
PdfView only closes its temporary rendered bitmaps.
See Using PDF Viewer for opening a document in Compose, state control, zoom configuration, render limits, custom loading and error UI, link handling, and search highlighting.
--enable-native-access=ALL-UNNAMED.manifest.properties, pdfium-adapter.js, pdfium.js,
and pdfium.wasm under the configured PDFium asset directory.The detailed setup commands are in Using PDF Core.
All current backends support:
Check PdfViewer.capabilities before calling optional APIs.
Not yet implemented: bookmarks, embedded thumbnails, text layout geometry on
the public backends, random-access sources, cropped rendering, forms, editing,
progressive loading/rendering, JavaScript, and XFA.
Unavailable operations throw PdfUnsupportedFeatureException.
| Library | English | 简体中文 |
|---|---|---|
pdf-core |
Using PDF Core | PDF Core 使用指南 |
pdf-viewer |
Using PDF Viewer | PDF Viewer 使用指南 |
PDF Viewer KMP is a PDFium-backed Kotlin Multiplatform library for reading, rendering, and displaying PDF documents.
Download the signed Android demo: pdf-viewer-kmp-demo.apk.
The project is split into two public libraries:
| Library | Purpose |
|---|---|
pdf-core |
Opens PDF documents and exposes metadata, page rendering, text, search, and links without requiring Compose UI. |
pdf-viewer |
Provides the PdfView Compose Multiplatform component with zoom, links, search state, and configurable result highlighting. It depends on pdf-core transitively. |
| Platform | Supported targets |
|---|---|
| Android | arm32, arm64, x86, x64 |
| iOS | device arm64, simulator arm64 |
| JVM desktop | macOS arm64/x64, Linux x64, Windows x64 |
| Browser | JavaScript, Wasm |
iOS x64 and Catalyst are not currently supported. The bundled PDFium build is
pinned to chromium/7961 and does not include V8 or XFA.
Add Maven Central and choose the library needed by commonMain:
repositories {
mavenCentral()
}
kotlin {
sourceSets {
commonMain.dependencies {
// PDF APIs only:
implementation("io.github.limuyang2:pdf-core:0.2.2")
// Or the Compose viewer. pdf-core is included transitively:
implementation("io.github.limuyang2:pdf-viewer:0.2.2")
}
}
}Use pdf-core when the application needs to inspect or render PDFs without the
built-in Compose UI:
import io.github.limuyang2.pdf.core.PdfPixelSize
import io.github.limuyang2.pdf.core.PdfRenderRequest
import io.github.limuyang2.pdf.core.PdfSource
import io.github.limuyang2.pdf.core.PdfViewer
suspend fun renderFirstPage(pdfBytes: ByteArray): ByteArray {
val document = PdfViewer.open(PdfSource.Bytes(pdfBytes))
try {
require(document.pageCount > 0)
val bitmap =
document[0].render(
PdfRenderRequest(
outputSize = PdfPixelSize(1200, 1600),
),
)
try {
return bitmap.copyPixels()
} finally {
bitmap.close()
}
} finally {
document.close()
}
}See Using PDF Core for passwords, metadata, text, search, links, bitmap formats, resource ownership, exceptions, and platform-specific setup.
pdf-viewer displays every page in a vertically scrolling Compose view:
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import io.github.limuyang2.pdf.core.PdfDocument
import io.github.limuyang2.pdf.viewer.PdfView
import io.github.limuyang2.pdf.viewer.rememberPdfViewState
@Composable
fun DocumentPreview(document: PdfDocument) {
val state = rememberPdfViewState()
PdfView(
document = document,
state = state,
modifier = Modifier.fillMaxSize(),
maxZoom = 4f,
gestureZoomEnabled = true,
)
}The caller owns PdfDocument and must close it when the screen is disposed.
PdfView only closes its temporary rendered bitmaps.
See Using PDF Viewer for opening a document in Compose, state control, zoom configuration, render limits, custom loading and error UI, link handling, and search highlighting.
--enable-native-access=ALL-UNNAMED.manifest.properties, pdfium-adapter.js, pdfium.js,
and pdfium.wasm under the configured PDFium asset directory.The detailed setup commands are in Using PDF Core.
All current backends support:
Check PdfViewer.capabilities before calling optional APIs.
Not yet implemented: bookmarks, embedded thumbnails, text layout geometry on
the public backends, random-access sources, cropped rendering, forms, editing,
progressive loading/rendering, JavaScript, and XFA.
Unavailable operations throw PdfUnsupportedFeatureException.