# Pdf-Viewer-安卓pdf-diy项目 **Repository Path**: joy20182018/pdfvieweranzhuopdfdiy ## Basic Information - **Project Name**: Pdf-Viewer-安卓pdf-diy项目 - **Description**: No description available - **Primary Language**: Java - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-09-06 - **Last Updated**: 2026-09-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
A Simple PDF Viewer library which only occupies around 80kb while most of the Pdf viewer occupies upto 16MB space.
## [New] Join our Discord Community [here](https://discord.gg/342ZFHX9mK)!
## ✨ Major Enhancements in Our PDF Viewer Library ✨
Hello Developers! We're thrilled to share some significant enhancements we've made to our PDF viewer library. We've fine-tuned several aspects to enhance your experience and ensure top-notch performance and security. Here's what's new:
- ### Jetpack Compose Ready 🚀
Step into the future with Jetpack Compose compatibility. Integrating our PDF viewer in Compose projects is now effortless, thanks to the PdfRendererViewCompose composable function.
- ### Turbocharged Performance 🏎️
We've optimized performance to handle PDFs more efficiently, ensuring swift and smooth operations, even with large documents.
- ### Local and on device files 📁
We have made it better and smooth with how local files are handled now, with latest permission policies.
- ### Seamless Orientation Adaptation 🔄
Our library now smartly preserves your page position during orientation changes, ensuring uninterrupted reading sessions.
- ### Enhanced File Path Security 🔐
Security just got stronger. We've revamped our file path handling to provide robust protection against directory traversal attacks, keeping your data safer than ever.
- ### Streamlined Caching System 💾
Experience efficiency at its best! Our refined caching strategy smartly manages storage, retaining only the most recent PDF file to optimize performance and space usage.
- ### Discreet Screenshot Prevention Feature 🚫📸
Privacy matters. Our new screenshot-blocking feature enhances data confidentiality in your app, keeping sensitive information secure from prying eyes.
- ### Flexible UI Customization ✨
Your design, your rules. Enjoy complete freedom in customizing the PDF viewer's interface, ensuring a perfect match with your app's style and theme. Render the view directly in your screen now.
- ### 'NoActionBar' Theme Compatibility 🎨
Seamless aesthetics, no matter the theme. Our library now gracefully integrates with 'NoActionBar' themes, ensuring a cohesive and appealing user interface.
Stay tuned as we continue to innovate and improve. Happy coding, and let's keep creating amazing experiences together!
## How to integrate into your app? ⚙️
We have migrated our library to Maven Central for easier integration and better reliability. To use the Pdf Viewer library in your project, add the following dependency to your `build.gradle` file:
#### Latest version:  without 'v'
### Groovy DSL
```gradle
dependencies {
// Replace 'latest-version' with the actual latest version number
implementation 'io.github.afreakyelf:Pdf-Viewer:latest-version'
}
```
### Kotlin DSL
```gradle
dependencies {
// Replace 'latest-version' with the actual latest version number
implementation("io.github.afreakyelf:Pdf-Viewer:latest-version")
}
```
### Requirements:
- Minimum SDK version: 21
- Compile & Target SDK version: 35 (updated since version 2.2.0)
### Java App Integration
If your Android app is written in **Java** (not Kotlin) and you encounter a crash at startup with:
> `java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/lifecycle/ProcessLifecycleOwner$initializationListener$1`
**The recommended fix is to update to the latest version of Pdf-Viewer**, which adds version
constraints for `lifecycle-process` and `lifecycle-runtime-ktx` (requiring a minimum of 2.8.7
during dependency resolution) and includes consumer ProGuard rules to prevent minifiers from
stripping these classes.
If you still see this crash after updating to the latest version of Pdf-Viewer, there are two possible causes with different remedies:
- **Dependency misresolution** (wrong `lifecycle-process` version resolved): Force the correct version in your `build.gradle`:
#### Groovy DSL
```gradle
dependencies {
implementation 'io.github.afreakyelf:Pdf-Viewer:latest-version'
// Force the correct lifecycle-process version if your dependency graph resolves an older one.
implementation 'androidx.lifecycle:lifecycle-process:2.8.7'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.7'
}
```
#### Kotlin DSL
```gradle
dependencies {
implementation("io.github.afreakyelf:Pdf-Viewer:latest-version")
// Force the correct lifecycle-process version if your dependency graph resolves an older one.
implementation("androidx.lifecycle:lifecycle-process:2.8.7")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.7")
}
```
- **R8/minifier stripping** (classes removed during shrinking): The library ships consumer rules in `consumer-rules.pro` that AGP/R8 automatically merges into your build. These rules will not take effect if `minifyEnabled false` is set for your release build type, if you are using a non-AGP shrinker pipeline, or if shrinker warnings are treated as errors and abort the build. In those cases, add the rules manually to your app's `proguard-rules.pro`:
```proguard
-keep,allowobfuscation class androidx.lifecycle.ProcessLifecycleOwner { *; }
-keep,allowobfuscation class androidx.lifecycle.ProcessLifecycleOwner$* { *; }
```
> **Note:** `kotlin-stdlib` and the lifecycle artifacts are included as transitive dependencies
> by the library and do not need to be declared separately in most cases.
## How to use the library?
Now you have integrated the library in your project but **how do you use it**? Well it's really easy. Just launch the intent with in following way: (Refer to [MainActivity.kt](https://github.com/afreakyelf/Pdf-Viewer/blob/master/app/src/main/java/com/rajat/sample/pdfviewer/MainActivity.kt) for more details.)
### Prerequisites
Ensure the library is included in your project's dependencies.
### Launching PDF Viewer
#### Opening PDF from a URL
To display a PDF from a URL, use the following code:
```kotlin
/* Parameters:
- context: The context of your activity.
- pdfUrl: URL of the PDF to be displayed.
- pdfTitle: Title of the PDF document.
- saveTo: Determines how to handle saving the PDF (e.g., ASK_EVERYTIME prompts the user each time).
- enableDownload: Enables downloading of the PDF. */
PdfViewerActivity.launchPdfFromUrl(
context = this,
pdfUrl = "your_pdf_url_here",
pdfTitle = "PDF Title",
saveTo = saveTo.ASK_EVERYTIME,
enableDownload = true
)
```
#### Opening PDF from Local Storage
To open a PDF stored in local storage:
```kotlin
/* Parameters:
- path: File path or URI of the local PDF.
- fromAssets: Set to false when loading from local storage. // FALSE by default
*/
PdfViewerActivity.launchPdfFromPath(
context = this,
path = "your_file_path_or_uri_here",
pdfTitle = "Title",
saveTo = saveTo.ASK_EVERYTIME,
fromAssets = false
)
```
#### Opening PDF from Assets
To open a PDF from the app's assets folder:
```kotlin
/* Parameters:
- path: File path or URI of the local PDF.
- fromAssets: Set to true when loading from assets.
*/
PdfViewerActivity.launchPdfFromPath(
context = this,
path = "file_name_in_assets",
pdfTitle = "Title",
saveTo = saveTo.ASK_EVERYTIME,
fromAssets = true
)
```
#### Loading PDF in a View
Load a PDF directly into a view:
Add PDF render view in your layout file
```xml