使用Google文档在webview中显示pdf文件(存储在谷歌驱动器中) [英] Display the pdf file(stored in google drive) in webview by using google docs
问题描述
我的pdf文件存储在某些网站上,例如:
我应该做些什么以便我可以使用自己的pdf从谷歌驱动器在webview中打开
我遵循 CommonsWare , Stuart Siegler , Samir Mangroliya 但没有任何效果。
:(
使用Google文档即可在互联网上查看任何pdf,甚至不需要将其下载到设备。这里是如何做到这一点的示例:
webview.loadUrl(http://drive.google.com/viewerng / viewer?embedded = true& url =+ pdf);
其中 pdf
是一个到你的PDF文件的字符串链接,所以你的情况就是:
字符串pdf =http://www.pdf995.com/samples/pdf.pdf;
webview.loadUrl(http://drive.google.com/viewerng/viewer?embedded=true&url= + pdf);
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
- I've downloaded the pdf doc
- uploaded in google drive
- Got my own link for pdf
- Trying to open that in
webview
using google docs - FAILED
Now 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. :(
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);
这篇关于使用Google文档在webview中显示pdf文件(存储在谷歌驱动器中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!