AndroidPDFPreview is a lightweight and easy-to-use library for displaying and interacting with PDFs in your Android applications. Built on top of PdfiumAndroid for decoding and AndroidPdfViewer for rendering, it delivers a smooth and user-friendly experience.
Note: This library is no longer actively maintained. Google is developing an official PDF library for Android as part of Jetpack. For new projects, consider using the Android PDF library when it becomes available. This repository will remain available for existing users but will not receive new features or active bug fixes.
- Display and interact with PDF documents
- Generate thumbnails from PDF pages for preview purposes
- Validate PDF documents for integrity, password protection, and corruption
- Support for gestures, zoom, and double tap
- Single page mode for e-book style reading with one page at a time
- Lightweight and easy to integrate into your Android apps
- Compatible with Android versions 5.1 and above
- 16KB page size support for Android 15+ devices
To install AndroidPDFPreview, add the following dependency to your project's Gradle file:
dependencies { implementation 'io.github.rhariskumar3:pdfpreview:1.2.1' }
-
Add a
PDFView
to your layout:XML
<com.harissk.pdfpreview.PDFView android:id="@+id/pdf_view" android:layout_width="match_parent" android:layout_height="match_parent" />
-
Load a PDF in your code:
// Optional: Validate document first (recommended) val isValid = PDFThumbnailGenerator.isDocumentValid(this, file) if (!isValid) { // Handle invalid document return } // Configure view settings (factory-time, set once) binding.pdfView.configureView { swipeHorizontal(true) enableAnnotationRendering(true) singlePageMode(true) // Enable single page mode for e-book experience spacing(10F) // in dp renderingEventListener(...) pageNavigationEventListener(...) gestureEventListener(...) linkHandler(...) } // Load document (runtime, can be called multiple times) binding.pdfView.loadDocument(file) { defaultPage(0) password(null) // Can be updated for password retry documentLoadListener(...) }
You can use PDFView in Jetpack Compose with AndroidView
. See Use Case Implementations for detailed examples.
- Asset
- File
- Uri
- ByteArray
- InputStream
- DocumentSource (custom)
AndroidPDFPreview now supports a modern architecture that separates factory-time configuration from runtime document loading. See API Documentation and Use Case Implementations for detailed information and examples.
- Password Retry: Update password without reconfiguring the entire view
- Document Switching: Load different documents while preserving view settings
- Compose-Friendly: Matches AndroidView's factory/update pattern
- Performance: View configuration is set once and reused
- Memory Efficient: Only document-specific data changes during runtime
Generate thumbnails from PDF documents for preview purposes. See Use Case Implementations for detailed examples.
Validate PDF documents before processing to check if they're valid, password protected, or corrupted. See Use Case Implementations for detailed examples.
For detailed API references, use case implementations, and project information, see:
- API Documentation - Comprehensive guide to all parameters, methods, and classes.
- Use Case Implementations - Practical examples for common scenarios.
- Changelog - List of changes and updates.
- Version History - Detailed version release notes.
- Docs README - Additional documentation overview.
This library is no longer actively maintained. Pull requests will not be accepted for new features. Only critical bug fixes for existing users may be considered on a case-by-case basis.
For existing users with critical issues, please file an issue on GitHub. General support and feature requests will not be addressed due to the library's maintenance status.
Thanks to these projects:
We hope you find AndroidPDFPreview to be a valuable tool for developing your Android apps.
Copyright 2023-2025 AndroidPDFPreview Contributors 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 https://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.
** Happy coding! **