Comments (11)
@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.
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.
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.
@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.
Yeah, System.out.println("file.exists() = " + file.exists());
shows true. I edited my comment to mention that.
from androidpdfviewer.
@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.
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.
@shyamsam please check if version 1.1.0 fixes issue
from androidpdfviewer.
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.
Library doesn't support remote content, so it works as expected. Glad that update fixed loading from internal memory.
from androidpdfviewer.
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)
- What is the freetype and littlecms version you are using? HOT 1
- Is not working for jbr 17 HOT 1
- Password protected PDFs not working HOT 1
- VivoY72.gitignore
- 无法显示pdf中的签名信息 HOT 1
- Blank space before PDF HOT 1
- autoScrolly
- AndroidPdfViewer with Supporting Android API >=21 HOT 1
- Duplicate conflict 'lib/arm64-v8a/libc++_shared.so' with OpenCV lib
- .
- PDF page half portion shown blur on many pdfs.
- Unable to go till end of page if autoSpacing set to true
- Cant' compile after adding library Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
- Future of the project HOT 15
- Primer proyecto
- 使用PdfViewer加载本地Pdf文件预览时,pdf文件中的内容会出现拉伸 HOT 2
- ❗Repo not found or no token provided HOT 2
- facing issue in going to specific page in search in pdf in kotline andriod studio
- UnsatisfiedLinkError with PDFium on Android 15 Emulator with 16 KB Page Size
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from androidpdfviewer.