ionic 如何打开 pdf 文件并在设备中查看 ios 和 android

ionic how to open pdf file and see in device for both ios and android

我有一个 pdf url。当我尝试在浏览器中打开它的工作时。但是当我尝试在 android 和 ios 设备中打开时。我的 pdf 文件无法打开查看。这是我的代码:

我的控制器:

$window.OpenLink = function(link) {
    window.open( link, '_system');
  };

我的 html 点击代码:

<div  class="col col-50 clsGrid" onclick="OpenLink('http://www.orimi.com/pdf-test.pdf')">

请帮帮我。如何打开我的 pdf 文件并在 android 和 ios 设备中查看。

提前致谢!!

安装插件

cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git

那就试试这个

<a class="item" href="#" onclick="window.open('http://www.orimi.com/pdf-test.pdf', '_system', 'location=yes'); return false;">
  Open pdf
                </a>

这里问过类似的问题。 Ionic framework PdfViewer

尝试使用这个 Phonegap 插件 https://github.com/ti8m/DocumentHandler 它非常适合我。

下面是我如何整合它的。

$scope.HandleDocumentPlugin = function () {
    if (DocumentViewer != null) {
        DocumentViewer.previewFileFromUrlOrPath(
            function () {
                console.log('success');
            }, function (error) {
                if (error == 53) {
                    console.log('No app that handles this file type.');
                    var alert = $ionicPopup.alert({
                        title: 'Alert!',
                        template: "There is no app installed that handles this file type."
                    });
                    alert.then(function (res) {

                    });
                }
            }, $scope.PDF_URL);
    }
    else if (DocumentHandler != null) {
        DocumentHandler.previewFileFromUrlOrPath(
           function () {
               console.log('success');
           }, function (error) {
               if (error == 53) {
                   console.log('No app that handles this file type.');
                   var alert = $ionicPopup.alert({
                       title: 'Alert!',
                       template: "There is no app installed that handles this file type."
                   });
                   alert.then(function (res) {

                   });
               }
           }, $scope.PDF_URL);
    }
    else {
        console.log("error");
    }
}