A Lightweight PDF Viewer Android library which only occupies around 125kb while most of the Pdf viewer occupies up to 16MB space.

Overview

Pdf Viewer For Android

A Simple PDF Viewer library which only occupies around 125kb while most of the Pdf viewer occupies upto 16MB space.

License

How to integrate into your app?

Integrating the project is simple, All you need to do is follow the below steps

Step 1. Add the JitPack repository to your build file. Add it in your root build.gradle at the end of repositories:

allprojects {
  repositories {
    ...
    maven { url "https://jitpack.io" }
  }
}

Step 2. Add the dependency

dependencies {
    implementation 'com.github.afreakyelf:Pdf-Viewer:Tag'
}

How to use the library?

Now you have integrated the library in your project but how do you use it? Well its really easy just launch the intent with in following way:

open_pdf.setOnClickListener {
            startActivity(
            
            // Use 'launchPdfFromPath' if you want to use assets file (enable "fromAssets" flag) / internal directory
           
                PdfViewerActivity.launchPdfFromUrl(           
                    context,                                                                      
                    "pdf_url",                                // PDF URL in String format
                    "Pdf title/name ",                        // PDF Name/Title in String format
                    "pdf directory to save",                  // If nothing specific, Put "" it will save to Downloads
                    enableDownload = false                    // This param is true by defualt.
                )
            )
        } 

That's pretty much it and you're all wrapped up.

Ui Customizations

You need to add the custom theme to styles.xml/themes.xml file and override the required attribute values. Parent theme can be either Theme.PdfView.Light or Theme.PdfView.Dark or the one with no actionbar from the application. Note: If parent is not one of the themes from this library, all of the pdfView attributes should be added to that theme.

<style name="Theme.PdfView.SelectedTheme" parent="@style/Theme.PdfView.Light">
    <item name="pdfView_backIcon">@drawable/ic_arrow_back</item>
    ...
</style>

Supported attributes

Attribute Name Type Expected changes
pdfView_backIcon drawable Navigation icon
pdfView_downloadIcon drawable Download icon
pdfView_downloadIconTint color Download icon tint
pdfView_actionBarTint color Actionbar background color
pdfView_titleTextStyle style Actionbar title text appearance
pdfView_progressBar style Progress bar style

Contributing

Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/NewFeature)
  3. Commit your Changes (git commit -m 'Add some NewFeature')
  4. Push to the Branch (git push origin feature/NewFeature)
  5. Open a Pull Request

Donations

If this project help you reduce time to develop, you can give me a cup of coffee :)

paypal

Author

Maintained by Rajat Mittal

Comments
  • Pdf has been corrupted.

    Pdf has been corrupted.

    Hello

    I am using PdfDocument to crerate PDF file. I am saving this file to app's Internal filesDir. Now when I run below code I am getting "Pdf has been corrupted" Toast message

    startActivity(new PdfViewerActivity().Companion.launchPdfFromPath(Activity4.this, file.getAbsolutePath(), "", "", false));

    So what can I do?

    Thank you

    bug 
    opened by karishmapujara 10
  • Jitpack version 1.0.8 is empty (v1.0.8 works).

    Jitpack version 1.0.8 is empty (v1.0.8 works).

    The 1.0.8 release on Jitpack is empty / NotFound: https://jitpack.io/com/github/afreakyelf/Pdf-Viewer/1.0.8/ but the version name with a v prefix works: https://jitpack.io/com/github/afreakyelf/Pdf-Viewer/v1.0.8/

    opened by DanielNovak 3
  • Pinch zoom feature request

    Pinch zoom feature request

    Is your feature request related to a problem? Please describe. I'm currently using PdfRendererView in my project. I want to add pinch-to-zoom functionality to it.

    Describe the solution you'd like I would like to enable this feature with a boolean flag, such as: pdfRenderView.isPinchZoomEnabled = true

    Describe alternatives you've considered Not possible currently.

    opened by ugurcany 2
  • Possible with JSON items?

    Possible with JSON items?

    I'm working on an app that has pdf urls in a json response, but the library doesn't seem to work with those. Do you possibly have a potential workaround and use for this?

    opened by DrewStephensCoding 2
  • Add change page text

    Add change page text

    Ui Page number

    You need to add the custom string to strings.xml file and override the required strings.xml values.

    Default:

    <string name="pdfView_page_no">%1$s of %2$s</string>
    

    Custom:

    <string name="pdfView_page_no" >%1$s / %2$s</string>
    

    #hacktoberfest

    Please add a hacktoberfest topic

    hacktoberfest-accepted 
    opened by chihung93 1
  • Give the PdfRenderView item a default height

    Give the PdfRenderView item a default height

    Thanks for your nice work. English is not my first language, I will try my best to describe my problem.

    I implemented my own PdfViewerActivity by using PdfRendererView. After opening a big pdf file, like more than 200 pages, the render core will try to build the bitmap all of the pages. This is because that the height of the recycler view item is wrap_content, which means 0 pixel. So the recycler view will try to load as more items as possible which seems like "block" the rendering. And, buildBitmap runs in a GlobalScope, the jobs won't be canceled when activity is destroyed. After close the large pdf and try to open a small pdf file, the rendering is still blocked since there are still lots of jobs remaining.

    I think this can be fixed by giving list item a default height, such as 480dp, so that the recycler view won't request a lots of buildBitmap jobs.

    opened by Loong-T 1
  • Gradle plugin update to 7.2, target SDK 32, Added Jetpack ViewBinding for example project, updated all dependencies

    Gradle plugin update to 7.2, target SDK 32, Added Jetpack ViewBinding for example project, updated all dependencies

    • Set target and compile SDK version to API 32. • Upgraded Gradle version to 7.1.2. • Built project in Android Studio 2021.1.1 Patch 2 (Bumblebee). • Added Java 11 support to project. • Added Jetpack ViewBinding support to example project. • Updated project Kotlin version to 1.6.10 • Updated all internal dependencies. • Upgraded project version to 1.1

    opened by BharathVishal 1
  • feature: enable customizations for ui

    feature: enable customizations for ui

    Add customizations for these elements/attributes

    • ActionBar background color
    • ActionBar title text appearance
    • Navigation icon
    • Navigation icon tint
    • Download icon
    • Download icon tint
    opened by KaungMyat-Min 1
  • App crash when minimise and reopen app.

    App crash when minimise and reopen app.

    App crashed Fatal Exception: java.lang.RuntimeException: Unable to stop activity {com.letzconnect/com.rajat.pdfviewer.PdfViewerActivity}: java.lang.IllegalStateException: Already closed To Reproduce Steps to reproduce the behavior:

    1. open PdfViewerActivity
    2. minimize the app
    3. Reopen the app from the minimized tray or from the launcher icon.
    4. the app will get crashed

    Cause onStop() binding.pdfView.closePdfREnder() if you cant reproduce the case ping me.

    bug 
    opened by vicky-droid 1
  • Loading and spacing

    Loading and spacing

    • Added pdfView_page_margin as an attribute to change spacing (Right, Left, Top, Bottom) from the pages Or use the following attribute to add space for each edges:
    <com.rajat.pdfviewer.PdfRendererView
        android:id="@+id/pdfView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:pdfView_divider="@drawable/divider"
        app:pdfView_engine="internal"
        app:pdfView_enableLoadingForPages="true"
        app:pdfView_page_marginRight="10dp"
        app:pdfView_page_marginLeft="10dp"
        app:pdfView_page_marginTop="5dp"
        app:pdfView_page_marginBottom="5dp"
    /> 
    
    • Added loading view for each page. It's available by using pdfView_enableLoadingForPages attribute.
    • Optimise rendering PDF process by using CoroutineScope instead of GlobalScope

    Breaking Changes

    • Added night/light mode background for PdfViewerActivity. If you enable spacing, it will show the background of this activity.
    • Remove background from the list of pages (PinchZoomRecyclerView) to let developers add a custom background for PDF viewer. It may affect to see the PDF viewer result by showing the parent background.

    Gif: ezgif-1-7e7bce22d1

    opened by Husseinhj 0
  • Double Tap to Zoom

    Double Tap to Zoom

    Please add the Double Tap to Zoom feature, right now user's are not aware the PDF can be zoomed or not, some users don't explicitly try to Pinch to Zoom and leave it thinking the PDF can not be zoomed. It'll be great if Double Tap to Zoom can be by default.

    opened by surajdevelops 0
  • PDF has been corrupted

    PDF has been corrupted

    When I am using the v1.0.1 it's throwing the error PDF has been corrupted but when I am downgrading it to v1.0.6 then it's working fine.

    Kindly revert any changes if you have done in v1.0.1 which might be causing the aformentioned error.

    opened by surajdevelops 2
  • External Control of File Name or Path

    External Control of File Name or Path

    Describe the bug We performed an analysis on our code with Veracode and detected the follow flaw on library, especifically on class PdfRendererCore.kt

    CWE-73: External Control of File Name or Path Flaw Category: Directory Traversal Description: The software allows user input to control or influence paths or file names that are used in filesystem operations.

    This could allow an attacker to access or modify system files or other files that are critical to the application. Path manipulation errors occur when the following two conditions are met:

    1. An attacker can specify a path used in an operation on the filesystem.
    2. By specifying the resource, the attacker gains a capability that would not otherwise be permitted. For example, the program may give the attacker the ability to overwrite the specified file or run with a configuration controlled by the attacker.

    Attack Vector: pdfViewer/src/main/java/com/rajat/pdfviewer/PdfRendererCore.kt: 52 and pdfViewer/src/main/java/com/rajat/pdfviewer/PdfRendererCore.kt: 65

    Additional context Veracode scan is required by our client and managed by him in regards to the process to point out a false negative. So it would be nice to point out if there are any risks or changes that can be made. Thanks.

    opened by willianfs 0
  • Why it takes so much time to load Pdf  and its did not loads properly when we are having more pages in Pdf?

    Why it takes so much time to load Pdf and its did not loads properly when we are having more pages in Pdf?

    When there are more than 10 pages in a Pdf File then it takes so much time to load and its did not loads pages properly when we are having more pages in Pdf

    opened by RahulRaviandroid 0
Releases(v1.1.1)
A lightweight Kotlin friendly wrapper around Couchbase lite for Android.

CouchBaseKtx ?? Work In-Progress ?? A lightweight Kotlin friendly wrapper around Couchbase-lite for Android Read up a little bit of documentation abou

Jaya Surya Thotapalli 5 Feb 15, 2022
An tool to help developer to use Retrofit elegantly while using kotlinx.coroutines.

one An tool to help developer to use Retrofit elegantly while using kotlinx.coroutines. Feature Transform different data structs to one. {errorCode, d

ChengTao 30 Dec 27, 2022
The most complete and powerful data-binding library and persistence infra for Kotlin 1.3, Android & Splitties Views DSL, JavaFX & TornadoFX, JSON, JDBC & SQLite, SharedPreferences.

Lychee (ex. reactive-properties) Lychee is a library to rule all the data. ToC Approach to declaring data Properties Other data-binding libraries Prop

Mike 112 Dec 9, 2022
A Kotlin DSL wrapper around the mikepenz/MaterialDrawer library.

MaterialDrawerKt Create navigation drawers in your Activities and Fragments without having to write any XML, in pure Kotlin code, with access to all t

Márton Braun 517 Nov 19, 2022
Yet another booru viewer for Android

Yet another booru imageboards viewer for Android Download Preview Click Here Building You can build this app just like any other flutter app, for exam

Nauval Rizky 129 Jan 4, 2023
Location-history-viewer - Small compose-desktop app to view data from google's location history

Google Location History Takeout Viewer This application provides a minimalistic

Chris Stelzmüller 3 Jun 23, 2022
This lib implements the most common CoroutineScopes used in Android apps.

AndroidCoroutineScopes Starting from 0.26.0 release we should define a scope for new coroutines (docs). To avoid this boilerplate code I've created th

Adriel Café 15 Oct 3, 2022
An android lib that provides most commonly used utility function

Awesome-Utility An android lib that provides most commonly used utility function. It can help Android developers with supporting common utility functi

Ameer Hamza 2 Apr 5, 2022
A library for building Java only Zygisk/Riru modules.

A library for building Java only Zygisk/Riru modules.

Kr328 19 Dec 17, 2022
Most used extension methods for Kotlin

Extensify Most used extension methods for Kotlin Download Step 1. Add the JitPack repository to your build file allprojects { repositories {

Mobven 36 Aug 25, 2022
The most essential libraries for Kotlin Multiplatform development

Essenty The most essential libraries for Kotlin Multiplatform development. Supported targets: android jvm js (IR and LEGACY) iosArm64, iosX64 watchosA

Arkadii Ivanov 218 Jan 3, 2023
A simple Kotlin wrapper around Anvil.

AnvilKotlin A simple Kotlin wrapper around Anvil. The only purpose of this library is to provide type safety to Anvil through Kotlin. Nothing more, no

Andre Artus 15 Oct 3, 2022
A simple Kotlin multi-platform abstraction around the javax.inject annotations.

Inject A simple Kotlin multi-platform abstraction around the javax.inject annotations. This allows using the annotations in Kotlin common code so that

Christopher 43 Aug 17, 2022
Develop an API that moves a rover around on a grid

Mars Rover Kata Develop an API that moves a rover around on a grid. Rules: You are given the initial starting 2D point (x,y) of a rover and the direct

Alvaro Martin Rodriguez 1 Dec 17, 2021
SavedStateFlow - A Kotlin StateFlow wrapper around SavedStateHandle

SavedStateFlow SavedStateFlow is a Kotlin StateFlow wrapper around SavedStateHan

Andrew Steinmetz 13 Aug 4, 2022
DocuBox is a cloud based file storing app where you can securely store and access your documents from anywhere around the world

DocuBox is an android app ??in which you can securely upload your files on the cloud– from family pictures and audio recordings to spreadsheets, presentations and other confidential documents.

Vaibhav Jaiswal 26 Jan 3, 2023
Create an application with Kotlin/JVM and Kotlin/JS, and explore features around code sharing, serialization, server- and client

Practical Kotlin Multiplatform on the Web 본 저장소는 코틀린 멀티플랫폼 기반 웹 프로그래밍 워크숍(강좌)을 위해 작성된 템플릿 프로젝트가 있는 곳입니다. 워크숍 과정에서 코틀린 멀티플랫폼을 기반으로 프론트엔드(front-end)는 Ko

SpringRunner 14 Nov 5, 2022
Create an application with Kotlin/JVM and Kotlin/JS, and explore features around code sharing, serialization, server- and client

Building a Full Stack Web App with Kotlin Multiplatform 본 저장소는 INFCON 2022에서 코틀린 멀티플랫폼 기반 웹 프로그래밍 핸즈온랩을 위해 작성된 템플릿 프로젝트가 있는 곳입니다. 핸즈온 과정에서 코틀린 멀티플랫폼을

Arawn Park 19 Sep 8, 2022
:bouquet: An easy way to persist and run code block only as many times as necessary on Android.

Only ?? An easy way to persist and run code block only as many times as necessary on Android. Download Gradle Add below codes to your root build.gradl

Jaewoong Eum 479 Dec 25, 2022