Giter Site home page Giter Site logo

Comments (11)

shyamsam avatar shyamsam commented on June 28, 2024 1

@barteksc thanks for you reply,

am still facing the same issue as @ENOZA has mentioned in earlier comments. I have given the permission in the manifest.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />

Am downloading the file from a remote server to a folder in phone storage. If I go to that particular directory I could see that file exists there and am able to open that file with other pdf viewers. The error an getting is when an populating the pdf. The log is shown below:

com.shockwave.pdfium.PdfOpenException: Open document failed
at com.shockwave.pdfium.PdfiumCore.newDocument(PdfiumCore.java:72)
at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:61)
at    com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:32)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)

from androidpdfviewer.

barteksc avatar barteksc commented on June 28, 2024

Environment.getExternalStorageDirectory() returns File, you have to call Environment.getExternalStorageDirectory().getAbsolutePath() to get String. Also, to read files from external storage you need <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> in your manifest

from androidpdfviewer.

ENOZA avatar ENOZA commented on June 28, 2024

barteksc, thank you for your PDF library for Android.
This is something I have been trying to find for a long time.

Since File.toString() usually returns the same value as File.getAbsolutePath(), it seems shyamsam's code is not a problem.

My code is almost the same as shyamsam's.

      File file = new File(Environment.getExternalStorageDirectory(), "pdf/sample.pdf");

      System.out.println("file.exists() = " + file.exists());

      pdfView.fromFile(file)
        .defaultPage(1)
        .showMinimap(false)
        .enableSwipe(true)
        .load();

file.exists() returns true but I also get the following error message when I try to load a PDF file on the internal memory of my device.

com.shockwave.pdfium.PdfOpenException: Open document failed

Of course, in my manifest, I put the following permission request.

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Here is my stack trace.

com.shockwave.pdfium.PdfOpenException: Open document failed
     at com.shockwave.pdfium.PdfiumCore.newDocument(PdfiumCore.java:72)
     at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:85)
     at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:37)
     at android.os.AsyncTask$2.call(AsyncTask.java:288)
     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
     at java.lang.Thread.run(Thread.java:841)

When I use fromAsset(), it works perfectly.
Only when I use fromFile() it gives the error as shown above.

Thank you for checking.

from androidpdfviewer.

barteksc avatar barteksc commented on June 28, 2024

@ENOZA You are right with File.toString.
Does System.out.println("file.exists() = " + file.exists()); show true? I see that File.toString() returns path without trailing slash, so it is necessary to write "/pdf/sample.pdf" instead of "pdf/sample.pdf".

from androidpdfviewer.

ENOZA avatar ENOZA commented on June 28, 2024

Yeah, System.out.println("file.exists() = " + file.exists()); shows true. I edited my comment to mention that.

from androidpdfviewer.

barteksc avatar barteksc commented on June 28, 2024

@ENOZA Sorry, I didn't notice that you are using 2nd argument of File constructor. Unfortunately I can't reproduce this behavior on 3 devices, maybe it's something bigger. You get exception from Pdfium, so maybe it has problem with opening your file, could you try with another one? I don't have any other ideas now.

from androidpdfviewer.

ENOZA avatar ENOZA commented on June 28, 2024

barteksc, thank you very much and I have to I apologize to you.
It seems it was because of my Android file system.
I copied a PDF file to my device by connecting it to a computer by a USB cable.
When I checked the file size on the device I realized it was zero.... (It existed there but it was an empty file).
I am sorry for my not noticing it.
When I disconnected the USB cable, the file size was restored to the original size and AndroidPdfViewer perfectly render the PDF file!

from androidpdfviewer.

barteksc avatar barteksc commented on June 28, 2024

@shyamsam please check if version 1.1.0 fixes issue

from androidpdfviewer.

shyamsam avatar shyamsam commented on June 28, 2024

Hi @barteksc ,

Thanks for the update. But am sorry to say that am still facing some issues,
As per the latest library am trying to load the pdf from a remote server. There am getting File not Found Exception. But when I load the same pdf url in browser is works. The logcat is shown below:

load pdf error
java.io.FileNotFoundException: No content provider:http://www.gnfiliaton.gr/sites/default/files/20131231103232738561744.pdf
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1104)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:959)
at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:816)
at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:771)
at com.github.barteksc.pdfviewer.DecodingAsyncTask.getSeekableFileDescriptor(DecodingAsyncTask.java:81)
at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:60)
at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:31)
at android.os.AsyncTask$2.call(AsyncTask.java:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)

But when I download the file to any local folder and calling pdfView.fromFile(), it works like charm. Thanks

from androidpdfviewer.

barteksc avatar barteksc commented on June 28, 2024

Library doesn't support remote content, so it works as expected. Glad that update fixed loading from internal memory.

from androidpdfviewer.

kondasusmithareddy avatar kondasusmithareddy commented on June 28, 2024

Pdf is not working in Kitkat version.When I Click on link,It Displaying Blank Page in My Emulator,Can u help me Please

from androidpdfviewer.

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.