My application has one button. If you click that button then it will display the web pages based on the web service response using webview.
It works properly for general links. But for links that have .pdf, a white screen gets displayed.
Is it possible to display the .pdf file using web view?
Would appreciate any help.
i used the following code
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://docs.google.com/gview?embedded=true&url="
+"http://www.kim-lai.com/images/Menu_100309.pdf");
It sounds like it could be trying to but there is no direct pdf rendering support in webview. Please look at the following question
android webview pdf
You may find the following question useful also
how to open a pdf file inside a webview for android?
EDIT
Android - Load PDF / PDF Viewer
Please also make sure you ask appropriate questions, prefrerably with code so that others can reproduce your problem and offer a solution. Do your own research!!! Stack overflow is not a magic site that does your work for you!!!
ADENDUM
You require internet permissions. Add this to your manifest.xml
SUPPLEMENTAL
I tried typing in the url into the browser and it tells me "Sorry, we are unable to retrieve the document for viewing or you don't have permission to view the document. "
mWebView.loadUrl("http://www.kimlai.com/images/Menu_100309.pdf");
Try like this, what do you see?
Related
My application has a list of pdf inside listview. The pdf is viewed inside the application using a webview that open a Google Docs sheet. It works fine for the first opened PDF, but
when going back and opening another PDF I got the error "whoops! There was a problem previewing this document". Is there some kind of limitation on opening PDF using google sheet. If so, how can I get full rights to open any PDF I want. can someone help please. Here is my code.
//---you need this to prevent the webview from
// launching another browser when a url
// redirection occurs---
wv.setWebViewClient(new Callback());
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setAllowFileAccess(true);
wv.loadUrl("https://docs.google.com/gview?embedded=true&url=" + SharepreferenceController.getPrefSavePdfInfo());
Try increasing the Version/Compatibility of the PDF. This worked for me.
Edit: I believe it is more of a size issue. When I changed the Version (from Acrobat 9.0 to 10.0) I had also optimized the PDF making it a smaller file. My larger files of the same Version still do not work.
I was having the same issue. What solved it for me was clearing the WebView cache before trying to load another PDF.
WebView webView=(WebView)findViewById(R.id.webView);
webView.clearCache(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("https://docs.google.com/viewer?url=" + url);
I'm just learning Android code and I've come upon a problem which I hope you can all help.
I want to display a PDF file from a URL from my application, I've got the PDF to display using a webView method however with having Adobe Reader and Polaris Office installed on my phone I was just wondering if I can load the URL and implement the PDF to be displayed using installed software?
My webView code is as follows:
WebView web = (WebView) findViewById(R.id.webView);
web.getSettings().setJavaScriptEnabled(true);
String pdf = "http://www.example-site.co.uk/pdf";
web.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdf);
I have searched several posts on here to no avail so any help will be much appreciated.
Searching for "pdf view intent" reveals stuff like that: How to render PDF in Android
If that doesn't help, you should try to implement a IntentChooser or directly ask the devs of your two apps on which intent they are listening.
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.
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 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.