A lightweight Android PDF Viewer Library powered by Mozilla's PDF.js, offering seamless PDF rendering and interactive features. Supports both Jetpack Compose and XML.
You can download apk from here
- Setup
1.1. Setup - Kotlin DSL
1.2. Setup - Groovy DSL - Usage
2.1. Jetpack Compose PdfViewer
2.2. XML PdfViewer
2.3. More Examples - See also
- Public Members
- License
- External Libraries used
- Contributions
View Kotlin DSL Setup
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle.kts or settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven("https://jitpack.io")
}
}
Step 2. Add the dependency
dependencies {
implementation("com.github.bhuvaneshw.pdfviewer:$module:$version")
}
Replace $module with compose, compose-ui, core or ui
Replace $version with latest version
Latest version:
View Module Usage Options
Minimal setup for rendering PDFs using Jetpack Compose.
implementation("com.github.bhuvaneshw.pdfviewer:compose:1.0.0")
Enhanced Compose viewer setup including PdfViewerContainer, PdfToolBar, and PdfScrollBar.
implementation("com.github.bhuvaneshw.pdfviewer:compose:1.0.0")
implementation("com.github.bhuvaneshw.pdfviewer:compose-ui:1.0.0")
Use the minimal setup for rendering PDFs.
implementation("com.github.bhuvaneshw.pdfviewer:core:1.0.0")
Includes PdfViewerContainer, PdfToolBar, and PdfScrollBar for a complete viewing experience.
implementation("com.github.bhuvaneshw.pdfviewer:core:1.0.0")
implementation("com.github.bhuvaneshw.pdfviewer:ui:1.0.0")
Note
If you are upgrading to v1.1.0 see Migration
View Groovy DSL setup
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle or settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.bhuvaneshw.pdfviewer:$module:$version'
}
Include compose dependency
val pdfState = rememberPdfState(source = "source")
PdfViewer(
pdfState = pdfState,
modifier = Modifier,
containerColor = Color.Transparent,
onReady = {
// Optional work
}
)
source (string) can be
- Asset Path, like "asset://sample.pdf" or "file:///android_asset/sample.pdf"
- Android Uri, like uri starting with "content://" from Document Picker
- Network url, like "https://example.com/sample.pdf"
- Direct file path like "/data/data/<YourPackageName>/files/sample.pdf" or
"file:///sdcard/Downloads/sample.pdf"(Not Recommended for accessing file from Internal Storage)
Include PdfViewer in your xml
<com.bhuvaneshw.pdf.PdfViewer
android:id="@+id/pdf_viewer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/md_theme_primaryContainer"
app:containerBackgroundColor="@android:color/transparent" />
Then call load function
// Kotlin
pdfViewer.onReady {
load("source")
}
// Java
PdfUtil.onReady(pdfViewer, () -> {
pdfViewer.load("source");
});
Warning
You should not access below members before the PdfViewer is initialized!
- PdfViewer.load()
- PdfViewer.loadFromAsset()
- PdfViewer.loadFromFileUri()
- PdfViewer.loadFromUrl()
- PdfViewer.ui
- PdfViewer.findController
- PdfViewer.pageScrollMode
- PdfViewer.pageSpreadMode
- PdfViewer.cursorToolMode
- PdfViewer.pageRotation
- PdfViewer.doubleClickThreshold
- PdfViewer.longClickThreshold
- PdfViewer.snapPage
- PdfViewer.pageAlignMode
- PdfViewer.singlePageArrangement
- PdfViewer.scrollSpeedLimit
- For Jetpack Compose examples see Jetpack Compose Examples
- For XML examples see XML Examples
View Public Members
isInitialized: Boolean
Indicates whether the PDF viewer has been initialized.
currentUrl: String?
The current URL of the loaded PDF document.
currentPage: Int
The current page number of the PDF document.
pagesCount: Int
The total number of pages in the currently loaded PDF document.
currentPageScale: Float
The scale factor of the current page (zoom level).
currentPageScaleValue: String
The current scale value of the PDF page (e.g., page-fit
, auto
).
properties: PdfDocumentProperties?
The properties of the currently loaded PDF document, such as title, author, etc.
ui: UiSettings
Returns the UiSettings
for the PDF viewer. Provides settings related to the UI provided by Mozilla's PDF.js.
findController: FindController
Returns the FindController
for the PDF viewer. Provides functionality for finding text in the PDF.
pageScrollMode: PageScrollMode
Defines the page scroll mode (e.g., vertical, horizontal, wrapped).
pageSpreadMode: PageSpreadMode
Defines the page spread mode (e.g., none, odd, even).
cursorToolMode: CursorToolMode
Defines the cursor tool mode (e.g., text select, hand tool).
load(url: String, originalUrl: String = url)
Loads a PDF file from the specified url
. The originalUrl
parameter is optional and defaults to the url
.
onReady(onReady: PdfOnReadyListener)
Registers a listener that gets called when the PDF viewer is initialized and ready.
addListener(listener: PdfListener)
Adds a listener to be notified of PDF events (e.g., page load).
removeListener(listener: PdfListener)
and removeListener(listener: PdfOnReadyListener)
Removes a previously added listener.
goToPage(pageNumber: Int)
Navigates to the specified page number in the PDF.
scrollToRatio(ratio: Float)
Scrolls the viewer to a specific ratio (0f - 1f) (calculated to offset).
scrollTo(offset: Int)
Scrolls the viewer to the specified offset.
goToNextPage()
Navigates to the next page in
7F74
the PDF.
goToPreviousPage()
Navigates to the previous page in the PDF.
goToFirstPage()
Navigates to the first page in the PDF.
goToLastPage()
Navigates to the last page in the PDF.
scalePageTo(scale: Float)
Zooms the current page to the specified scale factor.
zoomIn()
Zooms in on the current page.
zoomOut()
Zooms out on the current page.
zoomTo(zoom: Zoom)
Zooms to a specified zoom mode (e.g., PAGE_FIT
, PAGE_WIDTH
).
downloadFile()
Initiates the download of the currently viewed PDF file.
printFile()
- unstable
Prints the currently viewed PDF file.
startPresentationMode()
- unstable
Starts presentation mode, which is typically used for viewing PDFs in full-screen mode.
rotateClockWise()
Rotates the PDF clockwise by 90 degrees.
rotateCounterClockWise()
Rotates the PDF counter-clockwise by 90 degrees.
showDocumentProperties()
Displays the properties of the current PDF document (e.g., title, author).
reInitialize()
Re-initializes the PDF viewer, reloading the webview.
setContainerBackgroundColor(color: Int)
Sets the background color of the PDF viewer container.
Copyright 2025 Bhuvaneshwaran
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Contributions are welcome! If you have ideas for improvements, bug fixes, or new features, please feel free to:
- Fork the repository.
- Create a new branch for your changes.
- Make your changes and commit them.
- Push to the branch.
- Open a pull request.