GithubHelp home page GithubHelp logo

danjdt / android-pdfviewer Goto Github PK

View Code? Open in Web Editor NEW
139.0 5.0 30.0 1.6 MB

A Android PDF Viewer that render pdf using PdfRenderer and displays it in a RecyclerView.

License: MIT License

Kotlin 100.00%
android pdf-viewer pdf kotlin

android-pdfviewer's Introduction

Android PDFViewer

A Android PDF Viewer that render pdf using PdfRenderer + kotlin coroutines and displays it in a RecyclerView.

- This code will not be published as a library, but you can use it as you want.

- Requires API Level 21

How to use

    PdfViewer.Builder(rootView, lifecycleScope)
      .build()
      .load(file)

Setup options

    PdfViewer.Builder(rootView)
      .controller(PdfViewController)
      .quality(PdfPageQuality)
      .setZoomEnabled(Boolean)
      .setMaxZoom(Float)
      .setOnPageChangedListener(onPageChangedListener)
      .setOnErrorListener(onErrorListener)
      .setRenderDispatcher(Dispatchers.Default)
      .build()
      .load(file)

File load options

    pdfViewer.load(file : File)
    pdfViewer.load(url : String)
    pdfViewer.load(@RawRes resId : Int)
    pdfViewer.load(inputStream : InputStream)
    pdfViewer.load(uri : Uri)

Sample images/gifs

Scroll Zoom

android-pdfviewer's People

Contributors

danjdt avatar qz145 avatar sash0k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

android-pdfviewer's Issues

java.lang.ClassCastException: dagger.hilt.android.internal.managers.ViewComponentManager$FragmentContextWrapper cannot be cast to android.app.Activity

Hi,
I have encountered this issue when I used PdfViewer in fragment annotated @AndroidEntryPoint. It looks like a clash between Hilt and your library. Here is the stack trace and a snippet of my implementation of PdfViewer. I had to fix this issue by using this workaround. Could you fix it in the library?

W/System.err: java.lang.ClassCastException: dagger.hilt.android.internal.managers.ViewComponentManager$FragmentContextWrapper cannot be cast to android.app.Activity
W/System.err:     at com.danjdt.pdfviewer.PdfViewer.onFileLoaded(PdfViewer.kt:68)
W/System.err:     at com.danjdt.pdfviewer.decoder.LoadFileFromUrlAsyncTask.doInBackground(LoadFileFromUrlAsyncTask.kt:19)
W/System.err:     at com.danjdt.pdfviewer.decoder.LoadFileFromUrlAsyncTask.doInBackground(LoadFileFromUrlAsyncTask.kt:12)
W/System.err:     at android.os.AsyncTask$2.call(AsyncTask.java:334)
W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:246)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.processTask(ThreadPoolExecutor.java:1187)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
W/System.err:     at java.lang.Thread.run(Thread.java:784)
PdfViewer.Builder(binding.root)
    .setOnErrorListener(object : OnErrorListener {
        override fun onAttachViewError(e: Exception) {
            handleError(e)
        }
        override fun onFileLoadError(e: Exception) {
            handleError(e)
        }
        override fun onPdfRendererError(e: IOException) {
            handleError(e)
        }
    })
    .build()
    .load(args.url)

The PDF pages sequence changed.

Hi there,

thanks for the great project, however, I meet some troubles, for example, when I tried to show the PDF, I realized that its pages sequence changed.

Do you have any ideas how to fix it.

Thanks.

Is anyone maintaining?

Have you run out of time to maintain?

Its a great start but needs to be restructured to not assume all contexts are Activities (post instead of runonUiThread and similar changes)and to utilize coroutines instead of AsyncTasks... Another goal would be to use Compose instead of the standard views...

Also, it isn't hosted anywhere anymore and there is no Copyright notice to allow anyone at a reasonable company to allow for its use.

memory reservation

default of 100mb memory reservation in pool size seems a bit steep, any plans on improving this? technically you don't need to have more than 3 bitmaps allocated at any given time within the recyclerview

Click event for zoom view.

I customize the adapter view and add some views in it. I set the click event for these views. But, I don't get the right position of clicked view in it. Please help me.

Can I add a custom view?

as title
I want to add a button. When a user click a button, the pdf viewer add a customized view on pdf viewer. And the customized view can be moved or zoomed in/out when users move or zoom in/out the pdf.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.