在web视图中显示PDF视图、web、PDF

2023-09-07 02:57:42 作者:九月梦中醒

我想告诉我的应用程序的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

 
精彩推荐
图片推荐