如何在android中从服务器打开PDF文件
我有一个要求,其中有一个 URL = "http://www.example/Open.pdf"
现在,我想从我的 Android 应用程序直接打开这个 PDF
文件在默认的 PDF 查看器
中。
当我点击网页
上的此链接时,用户应该会看到一个使用此文档打开的默认 PDF 查看器。
注意:此文件不应存储在 SD 卡上。
我该如何继续此实施?
I have a requirement where there is a URL = "http://www.example/Open.pdf"
Now from my android application I want to open this PDF
file directly in the default PDF viewer
.
The moment I click on this link on the webpage
, user should be presented with a default PDF viewer opened with this document.
Note: This file should not be stored on the SD card.
How do I proceed for this implementation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我们可以在 webview 中打开 PDF 文件而不缓存它。在
"onCreate"
方法中编写以下代码。工作代码:
这里发生的是您使用 Google Docs 打开 PDF。使用上述方法的最大优点是PDF的延迟加载。 PDF 有多重并不重要。 Google 文档会处理它。
We can open PDF file in the webview without caching it. Write below code in
"onCreate"
method .Working code :
What happens here is you open the PDF using Google Docs. Best Advantage of using above method is the lazy loading of PDF. Does not matter how heavy the PDF is. Google Docs takes care of it.
您可以使用
googleDocs
在WebView
中查看 pdf。You can view the pdf in the
WebView
usinggoogleDocs
.您无法从应用程序中打开默认的 PDF 视图。
如果您的文件位于服务器上并且您想在不下载的情况下打开它,那么这也可能会带来更大的安全问题。如果像默认的 adobe reader 这样的外部应用程序可以访问您服务器上的内容,那么这就完全破坏了安全框架。
因此,最好的选择是启动浏览器或 webview 的新实例,并向用户显示 google 文档中的 PDF 文档。
这样用户就可以阅读文档并返回到应用程序的最新状态。
There is no way you can open a default PDF view from your application.
If your file is on the server and you want to open it without downloading then this might also pose a greater security concern. If external applications like default adobe reader can access the content on your server, then this is breaking the security framework altogether.
So, best option would be to launch a new instance of browser or webview and show the PDF document in google docs to the user.
This way user can read the document and get back to the recent state of the application as well.
除了使用 http://docs.google.com/gview?embedded=true&url=http://myurl.com/demo.pdf
do you have the others solution besides view pdf file using http://docs.google.com/gview?embedded=true&url=http://myurl.com/demo.pdf