
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 使用指南 |
| API reference | Dokka | — |
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 screenshots below were captured from the demo running on an OPPO Android device:
| Demo home | PDF viewer | Search and highlighting |
|---|---|---|
![]() |
![]() |
![]() |
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/8165 and does not include V8 or XFA.
Add Maven Central and choose the library needed by commonMain:
The dependency examples use the published 0.4.1 release. pdf-viewer depends
on Compose Multiplatform 1.13.0-rc01, a pre-release; Gradle resolves consumers
to it unless they declare a different version.
repositories {
mavenCentral()
}
kotlin {
sourceSets {
commonMain.dependencies {
// PDF APIs only:
implementation("io.github.limuyang2:pdf-core:0.4.1")
// Or the Compose viewer. pdf-core is included transitively:
implementation("io.github.limuyang2:pdf-viewer:0.4.1")
}
}
}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.closeAndAwait()
}
}Render individual tiles, allocating only the requested tile bitmap:
import io.github.limuyang2.pdf.core.PdfPixelRect
import io.github.limuyang2.pdf.core.PdfTileRenderRequest
// Call from a coroutine with an open document.
val tile = document[0].renderTile(
PdfTileRenderRequest(
fullPageSize = PdfPixelSize(4000, 6000),
tileBounds = PdfPixelRect(512, 1024, 1024, 1536),
),
)
try {
val pixels = tile.copyPixels() // 512 × 512 BGRA pixels
} finally {
tile.close()
}fullPageSize is the virtual canvas after rotation; no full-page bitmap of
that size is allocated. Tile bounds use top-left pixel coordinates with
exclusive right/bottom edges. For arbitrary PDF regions, use
PdfRenderRequest.sourceRect; see Region and tile rendering
for coordinate conventions.
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.PdfRenderMode
import io.github.limuyang2.pdf.viewer.PdfViewRenderOptions
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,
renderOptions = PdfViewRenderOptions(mode = PdfRenderMode.Auto),
)
}The default Auto mode keeps a full-page preview and loads visible tiles when
higher resolution is needed. FullPage uses full-page rendering; Tiled uses
tiles at each settled resolution. Unsupported backends fall back to full-page
rendering. maxRenderDimension caps full-page/preview images, not the virtual
tile canvas.
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 and tile configuration, caching, 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, 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 使用指南 |
| API reference | Dokka | — |
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 screenshots below were captured from the demo running on an OPPO Android device:
| Demo home | PDF viewer | Search and highlighting |
|---|---|---|
![]() |
![]() |
![]() |
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/8165 and does not include V8 or XFA.
Add Maven Central and choose the library needed by commonMain:
The dependency examples use the published 0.4.1 release. pdf-viewer depends
on Compose Multiplatform 1.13.0-rc01, a pre-release; Gradle resolves consumers
to it unless they declare a different version.
repositories {
mavenCentral()
}
kotlin {
sourceSets {
commonMain.dependencies {
// PDF APIs only:
implementation("io.github.limuyang2:pdf-core:0.4.1")
// Or the Compose viewer. pdf-core is included transitively:
implementation("io.github.limuyang2:pdf-viewer:0.4.1")
}
}
}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.closeAndAwait()
}
}Render individual tiles, allocating only the requested tile bitmap:
import io.github.limuyang2.pdf.core.PdfPixelRect
import io.github.limuyang2.pdf.core.PdfTileRenderRequest
// Call from a coroutine with an open document.
val tile = document[0].renderTile(
PdfTileRenderRequest(
fullPageSize = PdfPixelSize(4000, 6000),
tileBounds = PdfPixelRect(512, 1024, 1024, 1536),
),
)
try {
val pixels = tile.copyPixels() // 512 × 512 BGRA pixels
} finally {
tile.close()
}fullPageSize is the virtual canvas after rotation; no full-page bitmap of
that size is allocated. Tile bounds use top-left pixel coordinates with
exclusive right/bottom edges. For arbitrary PDF regions, use
PdfRenderRequest.sourceRect; see Region and tile rendering
for coordinate conventions.
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.PdfRenderMode
import io.github.limuyang2.pdf.viewer.PdfViewRenderOptions
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,
renderOptions = PdfViewRenderOptions(mode = PdfRenderMode.Auto),
)
}The default Auto mode keeps a full-page preview and loads visible tiles when
higher resolution is needed. FullPage uses full-page rendering; Tiled uses
tiles at each settled resolution. Unsupported backends fall back to full-page
rendering. maxRenderDimension caps full-page/preview images, not the virtual
tile canvas.
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 and tile configuration, caching, 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, forms, editing,
progressive loading/rendering, JavaScript, and XFA.
Unavailable operations throw PdfUnsupportedFeatureException.