My pdf file is stored in some website ex: http://www.pdf995.com/samples/pdf.pdf
Now I can't rely on other websites for my app. So
webview
using google docsNow the links are as follows
pdf stored in other website link: "http://www.pdf995.com/samples/pdf.pdf"
Sharable link of pdf saved in google drive: "https://drive.google.com/open?id=0B8e4zX5Y1S0XV0U0UTZJOUVma00"
If it's preceded with google docs : "https://docs.google.com/gview?embedded=true&url=https://drive.google.com/file/d/0B8e4zX5Y1S0XV0U0UTZJOUVma00/view"
Result,
Other websites may change their url at anytime. Can't rely on it.
If I use the google drive link alone, then it is opening in web browser not within the app.
If preceded with google docs, it is not resulting in a pdf doc. I get something like this.
What should be done so that I can use my own pdf from google drive to open in webview
I've followed CommonsWare, Stuart Siegler, Samir Mangroliya But nothing works. :(
I have a WebView, and the link to my pdf stored in google drive is:
String myPdfUrl = "https://drive.google.com/file/d/1fQfqgEmz-AiCpdHEIh7SNwdnAkQFqDQp/view";
Don't forget "/view".
And my java code for display:
private void displayWebView() {
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
view.loadUrl(myPdfUrl);
return true;
}
});
webView.loadUrl(myPdfUrl);
}
And add @SuppressLint("SetJavaScriptEnabled")
above onCreate()
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act
you can view any pdf on the internet using google docs even without downloading it to the device. Here is the sample of how to do it:
webview.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf);
Where pdf
is a string link to your PDF file. So in your case it will be:
String pdf = "http://www.pdf995.com/samples/pdf.pdf";
webview.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With