在web视图中显示PDF [英] Display PDF in webview

查看:145
本文介绍了在web视图中显示PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想告诉我的应用程序的PDF文件。我的web服务给我的PDF格式,我想将它下载到SD卡上,然后我想表明的PDF通过web视图我的应用程序。

I want to show a pdf in my application. My webservice gives me the pdf and I want to download it to sd card and then I want show that pdf in my app through webview.

推荐答案

我也与Android的PDF显示了一段时间的问题挣扎。我做了同样的方法,因为你下载的PDF到SD卡中提及,但我没能比使用preinstalled的Andr​​oid应用程序,它可以做的PDF开口(例如Adobe Reader或类似的),否则打开它。我认为这是不可能的,以查看PDF中的WebView小部件。原因很简单,就是包括web视图不支持插件,例如Adobe阅读器(参见:的 http://osdir.com/ml/Android-Developers/2010-09/msg03331.html

I was also struggling with Android PDF showing problem for some time. I did the same approach as you mentioned with downloading the PDF to the SD card, but I did not manage to open it up otherwise than using a preinstalled Android App which could do the PDF opening (e.g. Adobe Reader or similar). I think that it's not possible to view the PDF in a WebView widget. The reason is simply that the included webview does not support plugins like adobe reader (see: http://osdir.com/ml/Android-Developers/2010-09/msg03331.html)

您可以使用一个Intent调用方便地打开下载的PDF:

You can easily open up the downloaded PDF using an Intent call:

   File file = new File("/sdcard/filename.pdf");
   Uri path = Uri.fromFile(file);
   Intent intent = new Intent(Intent.ACTION_VIEW);
   intent.setDataAndType(path, "application/pdf");
   intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
   startActivity(intent);

由于这项技术开辟了PDF浏览器直接后,我的应用程序,使此调用,后退按钮将用户直接返回给应用程序,所以感觉像PDF浏览是我的应用程序的一部分的事实。

Due to the fact that this technique opens up the PDF viewer directly after my application makes this call, the back button takes the user directly back to the app, so it feels like the pdf viewing is part of my app.

希望这会有所帮助,最好的问候

Hope this helps, best regards

这篇关于在web视图中显示PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆