Git Product home page Git Product logo

Comments (20)

wei-spring avatar wei-spring commented on September 7, 2024 5

hi ,you can also change .pdf file from assets to res/raw ,then everything is ok.
change code :
mFileDescriptor = context.getAssets().openFd("sample.pdf").getParcelFileDescriptor();
to
Resources res = context.getResources(); mFileDescriptor = res.openRawResourceFd(R.raw.sample).getParcelFileDescriptor();

from android-pdfrendererbasic.

wangchauyan avatar wangchauyan commented on September 7, 2024 3

@swetakadam I think you might upgrade gradle version to 2.2.0, when I upgrade gradle version to 2.2.0, then this crash will happen.
So, you should keep gradle version as 2.1.2.

@yaraki
I also create a PR, please have a look

from android-pdfrendererbasic.

jifffffy avatar jifffffy commented on September 7, 2024

Hi, I have the same problem:
java.io.IOException: not create document. Error:
at android.graphics.pdf.PdfRenderer.nativeCreate(Native Method)
at android.graphics.pdf.PdfRenderer.(PdfRenderer.java:153)
at com.example.android.pdfrendererbasic.PdfRendererBasicFragment.openRenderer(PdfRendererBasicFragment.java:141)

 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.pdf.PdfRenderer.getPageCount()' on a null object reference
        at com.example.android.pdfrendererbasic.PdfRendererBasicFragment.showPage(PdfRendererBasicFragment.java:163)
        at com.example.android.pdfrendererbasic.PdfRendererBasicFragment.onViewCreated(PdfRendererBasicFragment.java:101)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:908)
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
        at android.app.BackStackRecord.run(BackStackRecord.java:834)
        at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
        at android.app.Activity.performStart(Activity.java:6005)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288)

            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
            at android.app.ActivityThread.access$800(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

the demo is working, I only change the sample.pdf to my own pdf.

from android-pdfrendererbasic.

yaraki avatar yaraki commented on September 7, 2024

That error means that mPdfRenderer = new PdfRenderer(mFileDescriptor) in the openRenderer method was not called, which will not happen just by adding some permissions or replacing the PDF file. What else have you changed? Did you change the logic around openRenderer? Feel free to reopen the issue if this doesn't work.

from android-pdfrendererbasic.

jadiaheno avatar jadiaheno commented on September 7, 2024

i have the exact same problem

from android-pdfrendererbasic.

namealperalp avatar namealperalp commented on September 7, 2024

Same problem w aide ide

from android-pdfrendererbasic.

joselitofilho avatar joselitofilho commented on September 7, 2024

I have the same problem.

from android-pdfrendererbasic.

gunjot-mansa avatar gunjot-mansa commented on September 7, 2024

Any solution to the issue?

from android-pdfrendererbasic.

swetakadam avatar swetakadam commented on September 7, 2024

any solution still the same ... I have just replaced file ... not changed any other code

from android-pdfrendererbasic.

swetakadam avatar swetakadam commented on September 7, 2024

@yaraki -- it is not working please can we open this again

from android-pdfrendererbasic.

yaraki avatar yaraki commented on September 7, 2024

Can you provide a project to reproduce the issue?

from android-pdfrendererbasic.

swetakadam avatar swetakadam commented on September 7, 2024

@yaraki -- I solved the issue for me ... .. check this discussion they provide deeper details https://code.google.com/p/android/issues/detail?id=82841 ...
sorry could not give example project ... even if you checkout google sample .. and replace sample.pdf to some other file in assets .... it will keep displaying sample.pdf .. or sometimes keep throwing above error ..

My fix was --

I am not reading from assets ... assets directory is causing issues
SDcard -- files on it work as a charm ..

Another important change done by me is -- the code from onDetach is moved to onDestroy ...

I will investigate further about assets directory .. for now I wasted a day and half on this example just to change the file

from android-pdfrendererbasic.

yaraki avatar yaraki commented on September 7, 2024

As README.md says, if you are using a file from assets, include this in your build.gradle.

android {
    aaptOptions {
        noCompress "pdf"
    }
}

from android-pdfrendererbasic.

swetakadam avatar swetakadam commented on September 7, 2024

I did that too .. as filed from assets are compressed ...

from android-pdfrendererbasic.

yaraki avatar yaraki commented on September 7, 2024

Chauyan, thanks for the report. It seems that Android gradle plugin 2.2.0 has a bug with aaptOptions: https://code.google.com/p/android/issues/detail?id=224273

from android-pdfrendererbasic.

wangchauyan avatar wangchauyan commented on September 7, 2024

@yaraki , thank you for reporting.

from android-pdfrendererbasic.

vijaypwr61 avatar vijaypwr61 commented on September 7, 2024

@yaraki
I m using xamarin studio so in xamarin studio it is app.csprj file I tried that "" but error says
"Java.io.extension: can not create file error 3"

I searched lot but couldnt find answer

from android-pdfrendererbasic.

vijaypwr61 avatar vijaypwr61 commented on September 7, 2024

@hpu-spring87

I liked your trick so when I was trying it into my project my xamarin studio extenion for visual studio 2015 crashed so couldnt tried. I ll try

from android-pdfrendererbasic.

vijaypwr61 avatar vijaypwr61 commented on September 7, 2024

@hpu-spring87
I tried your logic but same erro
Java.IO.IOException: cannot create document. Error: 3

from android-pdfrendererbasic.

vijaypwr61 avatar vijaypwr61 commented on September 7, 2024

I found answer for my problem here
the 4th Comment from "This allows the sample to work:
"

from android-pdfrendererbasic.

Related Issues (20)

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.