javascript phonegap android中的pdf查看器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12003441/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 15:01:47  来源:igfitidea点击:

pdf viewer in phonegap android

javascriptandroidhtmlcordova

提问by Leon van der Veen

I'm looking for a pdf viewer for Android using Phonegap 2.0. I tried the childbrowser plugin wich worked on IOS but not on Android. I tried this http://www.giovesoft.com/2011/08/download-and-open-pdf-with-phonegap.htmlbut that didn't work either, I get error messages like PhoneGap is not defined at file And Cannot call method "showPdf" of undefined.

我正在寻找使用 Phonegap 2.0 的 Android pdf 查看器。我尝试了适用于 IOS 但不适用于 Android 的子浏览器插件。我试过这个http://www.giovesoft.com/2011/08/download-and-open-pdf-with-phonegap.html但这也不起作用,我收到错误消息,如文件中未定义 PhoneGap 并且无法调用未定义的方法“showPdf”。

I hope someone can help me.

我希望有一个人可以帮助我。

Thanks in advance!

提前致谢!

回答by Mohammad Razeghi

you can use pdf.js :

你可以使用 pdf.js :

pdf.js is an HTML5 technology experiment that explores building a faithful and efficient Portable Document Format (PDF) renderer without native code assistance.

pdf.js 是一项 HTML5 技术实验,旨在探索在没有本机代码帮助的情况下构建忠实且高效的可移植文档格式 (PDF) 渲染器。

https://github.com/mozilla/pdf.js

https://github.com/mozilla/pdf.js

回答by Ian Devlin

I answered a similar question already (see Open PDF with PhoneGap in Android) but will do the same here. Use the ChildBrowser plugin as suggested in conjunction with Google Docs like so:

我已经回答了一个类似的问题(请参阅在 Android 中使用 PhoneGap 打开 PDF)但会在这里做同样的事情。按照建议将 ChildBrowser 插件与 Google Docs 结合使用,如下所示:

onclick='window.plugins.childBrowser.showWebPage(encodeURI("http://docs.google.com/viewer?url=' + pdfLink + '"));

This works fine for me and I have tested it in Android 2.1 up to 4.1.

这对我来说很好用,我已经在 Android 2.1 到 4.1 中对其进行了测试。

回答by Bhavya Anand

In Android, you can view the pdfs using Android Intents. This will show you all the pdf viewers available in your phone. You can select any and view the pdf

在 Android 中,您可以使用 Android Intents 查看 pdf。这将向您显示手机中可用的所有 pdf 查看器。您可以选择任何并查看pdf

Eg :

例如:

private void showPdfAndroid(String url) throws IOException {
    Intent intent = new Intent();
    intent.setAction(android.content.Intent.ACTION_VIEW);
    File file = new File(url);

    String extension = url.substring(url.lastIndexOf(".")+1);
    String type = "";

    if (extension.toLowerCase().equals("pdf")) {
        type = "application/pdf";
        Log.d("application/pdf", "application/pdf");
    } 

    intent.setDataAndType(Uri.fromFile(file), type);
    cordova.getActivity().startActivity(intent);

    Log.d("FileViewerPlugin", "View complete in" + url);


}

回答by Ashisha Nautiyal

Child browser don't support pdf viewing in android . better you use Google docs viewer for it in android . here in another stack overflow questionyou will get complete answer

子浏览器不支持在 android 中查看 pdf。最好在 android 中使用 Google 文档查看器。在另一个堆栈溢出问题中,您将获得完整答案

回答by user1638126

The childbrowser plugin which I tried with does not open the pdf in android phonegap. However, it works for iOS. Another solution to your plugin query could be to use the Open With plugin. There is one disadvantage that this plugin does not open the pdf in the app itself. You can use the downloader plugin to download files and then try out the childbrowser plugin to access this pdf, which I think should be the solution

我尝试使用的子浏览器插件无法在 android phonegap 中打开 pdf。但是,它适用于iOS。插件查询的另一个解决方案可能是使用 Open With 插件。此插件有一个缺点,即无法在应用程序本身中打开 pdf。您可以使用下载器插件下载文件,然后尝试使用子浏览器插件访问此pdf,我认为这应该是解决方案