How to open pdf file from SD card in webview in android - android

How to open Sd card pdf file in Webview without using Intent in Android?

You cant open pdf directly in android web browser.
Use Google Docs in a WebView Like this : Read pdf file from sd-card with the help of webview

How to open Sd card pdf file in Webview without using Intent in Android?
Generally, you can't. WebView does not have any native ability to display PDF files. You are welcome to attempt to get PDF.js to work, as is discussed in this Stack Overflow question.

Related

How to open a PDF file onclick of a button in Android?

I need to save PDF file when my app installs and then open it when a user clicks on a button. I found many solutions but was not able to integrate them into one.
Try this code, display pdf file from a file location (works from any file location, not SDcard specific)
How to open a PDF via Intent from SD card
I was doing this in work today and it is not that easy.
1) saving the file is not difficult any normal file code will work for a pdf file.
2) showing the pdf you have two options you can display a pdf in a webview if the device has internet access by displaying a Webview and loading google docs with you pdf file at the end of the url
3) or you can create an intent and see if the device has an application that will display the file, you will need to use a FileProvider to get it to run but there is a good post
https://developer.android.com/reference/android/support/v4/content/FileProvider.html

Is it possible to open pdf file store in sdcard/cache in webview?

I am downloading PDF file in my application and want to allow user to view it. Is it possible that using webview I can display that pdf file downloaded to SD Card or local memory.
As I know there is workaround in which I can provide the link of pdf file to google url which will open pdf in webview. But it lags and is very slow.
Basic answer, no. You can't open a PDF in a webview; so you either need to fire an Intent to open the file (the file can then open in the default installed app on the device); or write your own PDF reader.
Try to use pdf.js.
See http://www.worldwidewhat.net/2011/08/render-pdf-files-with-html5/
I downloaded its source and placed it in sdcard.
Then I use a WebView to load its index.htm.
It did show pdf file on a webView in sdcard in Android 4.0 device but sometime it show white page. I need to reload it and it finally can show.
Unfortunately, I also tested on Android 2.2 and 2.3 devices. They just show white page, nothing.
I know it make use of html5 canvas technology. I have checked on loading http://html5test.com/ on WebView and have tick on canvas element but still can't show pdf. Strange behaviour. Maybe really depends on Android version.

How to interact with internal anchors and embedded hyperlinks of pdf

I am developing an application that can read PDF as well as it interact the hyperlink and internal anchors.
I am using MuPDF library, which is embedded in Android.
I am able to read the PDF file but how i can read and perform action on internal link and hyperlink?
Can anyone has an idea, how can i read the link and when use clicked on it, it open related page in PDF or in browser.
MuPDF link.

Android - Load PDF / PDF Viewer

I want to display pdf contents on webview.
Here is my code:
WebView webview = new WebView(this);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("URL/Demo_PDF.pdf");
Problem:
When i am trying to run the application, at that time I am getting blank screen.
And also, if there is any PDF viewer then also suggest me !!
FYI, I have already set internet permission.
Finally, i got a solution, actually i made a trick to load a pdf file using Google Docs inside a webview:
webview.loadUrl("http://docs.google.com/gview?embedded=true&url=http://myurl.com/demo.pdf");
I'm sorry but WebView does not display PDF content.
What you might want is a PDF viewer that responds to the PDF MIME type.
Here are a couple of free open-source libraries you might want to check:
droidreader
apv pdf reader
You can try using mupdf (www.mupdf.com)
You can build a native code library (libmupdf.so) to be loaded onto your android project using the ndk.
This would ensure a lot faster rendering of pdf files...
check out the project at : http://mupdf.com/repos/mupdf/android/
WebView does not have a PDF plugin. You should store the PDF locally and open an intent for viewing that kind of content.

Display PDF in webview

I want to show a pdf in my application. My webservice gives me the pdf and I want to download it to sd card and then I want show that pdf in my app through webview.
I was also struggling with Android PDF showing problem for some time. I did the same approach as you mentioned with downloading the PDF to the SD card, but I did not manage to open it up otherwise than using a preinstalled Android App which could do the PDF opening (e.g. Adobe Reader or similar). I think that it's not possible to view the PDF in a WebView widget. The reason is simply that the included webview does not support plugins like adobe reader (see: http://osdir.com/ml/Android-Developers/2010-09/msg03331.html)
You can easily open up the downloaded PDF using an Intent call:
File file = new File("/sdcard/filename.pdf");
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Due to the fact that this technique opens up the PDF viewer directly after my application makes this call, the back button takes the user directly back to the app, so it feels like the pdf viewing is part of my app.
Hope this helps, best regards
As already answered here, the WebView can't render PDFs. You can do what it is said in the accepted answer in this question and try to open the PDF with the default PDF viewer in the device. If the device has no PDF viewer installed, a message will be displayed to the user.

Categories

Resources