I surfed a lot for this solution but everywhere I got same solution i.e. either use Intent and pass it to default/installed PdfReader applications, Other one is to use gview from googleDocs to load Pdfs online.
But my question is how can view my pdf offline in webview i.e. if user click on list of pdf in my application don't go to other application or google/gview .
I tried passing assets folder path but not working getting message in webview that "webpage is temporarily down or move permanently."
I also tried this link.. which describes to use pdfViewver.jar but that lib. has it's own issues that needs to be fixed.
any help will highly appreciated
But my question is how can view my pdf offline in webview
You can't. WebView cannot display PDFs on its own.
Related
I'm using Xamarin Forms with Android, I need to open a PDF from an URL in my WebView. For some reason, sometime the the Webview is blank. I've searched a lot on Internet and I found some solution that give me the same result, sometime the PDF in the PDF is showed without problem, sometime is a blank page. I'm using "https://drive.google.com/viewerng/viewer?embedded=true&url=" with no results, I'm using this solution ( https://acaliaro.wordpress.com/2017/11/30/open-a-pdf-inside-a-webview-in-xamarin-forms-android/ ) that describe exactly my problem but WebView still show me a blank page sometime.
So, why is so hard to open a PDF Url on Android in a WebView? There is some solution to fix this problem? I don't know what can i else do.
Android WebView not support .pdf file from website, infact, if you try to copy an url with .pdf extension in chrome browser, this will download the file and open in an app. So there is no way to show a PDF in an App in a simple way. But there are two solution:
On Google there are a lot solutions that tells you to download the PDF and show in an webview, but in my case I can't download a PDF and show.
You can write an .html page in your Server that can "wrap" the PDF sended with an URL in GET mode and show it in an .html page without problem ( using jsPDF is an example ) or by using this prefix ( http://drive.google.com/viewerng/viewer?embedded=true&url= ) but sometime i give a blank page, so i write my own pdf viewer. In this link ( https://acaliaro.wordpress.com/2017/11/30/open-a-pdf-inside-a-webview-in-xamarin-forms-android/ ) you can find another solution, but for some reason, it still doesn't works. Maybe because I'm on Android 5.0 device.
I am developing an Android application in which I have a WebView. I want to save the entire webpage loaded in this webview (Html + all resources + images + icons etc) into a folder and zip it and upload it to a server.
If you use WebView's saveWebArchive, then it is saved in archive format. How do I get the Html and images back from this archive? Is there any documentation for the format of this archive?
If I use addJavaScriptInterface to get the html as described here, I still have to copy the images and other resources from the webview cache dir (/data/data/your app package/cache/webviewCache/). However I did not find webview cache dir (/data/data/your app package/cache/webviewCache/) in Icecream Sandwich.
Is there a way to save the entire webpage displayed in webview along with resources in Android?
Thanks
If anyone is still interested, there is an open source project here that can read WebView's archive format (saved with saveWebArchive) and display it back in a WebView.
https://github.com/gregko/WebArchiveReader
I couldn't find details of the actual format yet.
You can use HTML 5 to store pages in the cache and load from the cache itself.
Caching is easy using HTML5, all you have to do is to make and refer a manifest file that holds information on what all elements need to be cached.
http://www.html5rocks.com/en/tutorials/appcache/beginner/
And here is a good way to implement the cache feature in your webview. http://alex.tapmania.org/2010/11/html5-cache-android-webview.html
Aman Gautam
I am using the following link inside a WebView to show a pdf file in my android application:
http://docs.google.com/gview?embedded=true&url=http://174.136.1.35/dev/android/1_android-Survey-Report-for-pdf-1200-x-768.pdf
This works, and displays the PDF, as you can see in the attached images. The problem I have is that
I want to disable the zoom controls, and the desktop and download
links.
Is this possible, and if so, how?
You are basically opening a web view and loading it with a webpage from the internet, specifically Google Docs. Without some special functionality built into the website, there isn't going to be way to get rid of the extra buttons, links, and labels you're seeing. Instead of this, you could download the PDF that your link is pointing to as a PDF and try to display that directly. There is a stack overflow question on this topic
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.
I have an app where I've button on a webpage that is rendered inside a webview.
Now on click of button , a pdf file gets downloaded , and the same would then need to be opened inside the same webview.
attach a download listener to the web view and change the url as follows..
"https://docs.google.com/gview?embedded=true&url=https://www.example.com/xxxxxyyyyyxz.pdf"
example
https://docs.google.com/gview?embedded=true&url=https://www.adobe.com/support/products/enterprise/knowledgecenter/media/c4611_sample_explain.pdf
it's a link used to open pdf without downloading it...
I hope it solves your problem..
I've found that the google viewer seems to work within the android browser for viewing online PDF files. You could build a link to your pdf so that it is displayed in the viewer. I've not tried doing that within a WebView though.
UPDATE
The link is dead, there is an explanation of how to get the functionality to still work at this link.
In case this link also dies, here is the relevant section:
While the page is no longer available as it redirects to Google Docs/Drive, you can still use the Google Docs Viewer. Paste this URL in a new tab:
https://docs.google.com/viewer?url=
and then paste the address of the document you want to view online. Here's an example:
https://docs.google.com/viewer?url=http://research.google.com/archive/bigtable-osdi06.pdf
I do not think that the present android chrome based browser can support pdf. There are discussion about the same in android forums ( ex: link1 link2)
Your best bet to show pdf is to have adobe pdf reader for android installed.(or concisely put, not possible in web view)
I don't think any browser other than Chrome supports rendering PDFs without a plugin or third party tool. It's probably easier to let the user use his own app to open PDFs.
I used the IText PDF library mentioned in this thread
Android : Is there any free PDF library for Android for a sample project. You could try getting using this API to get the PDF page as an image. I am not familiar with every aspect of Itext so it might have better way to do this.