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

问题描述 投票:7回答:2

我有一个pdf网址。当我尝试在浏览器中打开它时。但是,当我尝试在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设备中查看。

提前致谢 !!

html angularjs pdf ionic-framework hybrid-mobile-app
2个回答
1
投票

安装插件

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>

0
投票

类似的问题在这里问。 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");
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.