无法在 android 的 inappbrowser 中启动 pdf 文件 [英] Not able to launch a pdf file in inappbrowser in android

查看:21
本文介绍了无法在 android 的 inappbrowser 中启动 pdf 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在用户单击链接时在 inappbrowser 中显示 pdf.它在 ios 上运行良好,但在 android 上不起作用.我在我的项目中使用 IBM Worklight.以下是我使用的代码:

I have a requirement to show a pdf in inappbrowser when user clicks on a link. It is working fine in ios but not working on android. I am using IBM worklight for my project. Below is the code I have used:

window.open("pdfURL","_blank","location=yes");

在 ios 中,inappbrowser 启动并显示 pdf,但在 android 中,inappbrowser 启动但不显示任何内容

In ios the inappbrowser launches and displays the pdf but in android the inappbrowser is launches but no content is displayed

推荐答案

与内置 PDF 查看器的 iOS 不同 - Android 的 webview 没有内置 PDF 查看器.
这就是它在 Android 中会失败的原因.

Unlike iOS, which has a built-in PDF viewer - Android's webview does not have PDF viewer built-in.
This is why it is going to fail in Android.

您在 Android 中有 2 个选择:

You have 2 choices in Android:

  1. 使用 Google Docs 查看文件通过将文件存储在远程服务器并像这样重定向用户:window.open(encodeURI('https://docs.google.com/gview?embedded=true&url=http://www.your-server.com/files/your_file.pdf'), '_blank', 'location=yes,EnableViewPortScale=yes');

或者使用 Cordova 插件.例如这个(你可以在谷歌搜索更多).为此,您需要了解 如何创建 Cordova 插件-在 Worklight 中插入.

Or use a Cordova plug-in. For example this one (you can search in Google for more). For this, you'll need to learn how to create Cordova plug-ins in Worklight.

您可以在这里阅读更多选项:Phonegap InAppBrowser display pdf2.7.0

You can read more options here: Phonegap InAppBrowser display pdf 2.7.0

这篇关于无法在 android 的 inappbrowser 中启动 pdf 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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