I'm working on an application to view pdf files.
I have done viewing pdf files from the internet using the docs.google api. I want to try to make my laptop as the server or where the pdf file is located.
WebView webView=(WebView)this.findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAllowFileAccess(true);
webView.loadUrl("https://docs.google.com/viewer?url=http%3A%2F%2F10.0.2.2%2Fdrayber_beep%2FAndroid13Web.pdf");
The docs.google api cannot find the location, but when I try to click the download link given by the api, I was able to download it in the emulator and view it using a pdf reader.
Am I missing something? I would really appreciate your help. thanks
The url postet into a browser returns an Bad Request - Error.
https://docs.google.com/viewer?url=http%3A%2F%2F10.0.2.2%2Fdrayber%2Handbook.pdf
Related
i am working on Document fatch app and i need to show .doc,.docx,xls files from my external storage to my app as i able to view pdf using pdf viewer but not getting how to show these files.
There is an android branch of Java library docx4j, you can use it. Another option is using Webview, set:
webview.getSettings().setPluginsEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
and then pass link of your document to webview (it can also be local link). I am not sure that webview solution will work on all versions of Android, so docx4j is more generic solution.
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?
can we render pdf and show it on web view in android. kindly help me out
Yes you can load PDF in Webview using Google's gview, It is a trick.
Here you can have my solution for the same trick: Android - Load PDF / PDF Viewer.
You cant open PDF file directly in android web browser but using Google Docs Viewer. you can open it in android Browser like:
String webUrl="http://myweb.com/demo.pdf";
mWebView.loadUrl("https://docs.google.com/gview?embedded=true&url="+ webUrl);
Unluckily, Google has changed the api... When you try to load the docs.google.com/gview url, the web view is redirect to the new drive.google.com/viewerng that can't render the pdf in the Android WebView...
Any other clever solution? :D
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.