2016-04-29 44 views
2

我正在开发具有离子框架的应用程序,我需要显示pdf。在离子应用程序中显示pdf

我读过在互联网上一番,发现此指令以使用

https://github.com/winkerVSbecks/angular-pdf-viewer

的问题是,我有问题,该指令与我的应用程序离子整合。

我已经做了指示的步骤:

  1. 凉亭安装角PDF查看器

  2. 包括路径到lib,AngularJS和PDFJS:(这里我修改的路径)

    <script src="lib/pdfjs-dist/build/pdf.js"></script> 
        <script src="lib/angular/angular.js"></script> 
        <script src="lib/angular-pdf-viewer/dist/angular-pdf-viewer.min.js"></script> 
    
  3. 包含的lib在你的角度应用的依赖:

    var app = angular.module('App', ['pdf']); 
    

然后我把这个模板

<pdf-viewer delegate-handle="my-pdf-container" url="www.publishers.org.uk/_resources/assets/attachment/full/0/2091.pdf" scale="1" show-toolbar="true" ></pdf-viewer> 

但我得到这个错误

[$parse:syntax] Syntax Error: Token 'pdf' is an unexpected token at column 64 of the expression

我在做什么错?

在此先感谢!

回答

1

我相信url值是指你的范围。所以鉴于你有$ scope.pdf =“你想要的网址”,你可以在标签中使用url =“pdf”。

+0

这似乎工作!但现在我有一个404错误的网址,但我100%确定网址是好的,因为如果我在浏览器中打开它的作品。该网址必须是本地的或可以www.aaaaa.com? – joacoleza

+0

当您使用远程调试进行检查时,它真的是404错误吗?这可能是CSP问题。确认您在远程调试控制台中看到的内容。 –

+0

它不工作,因为不知何故,这是它正在寻找的路线: “file:///android_asset/www/www.adobe.com/enterprise/accessibility/pdfs/acro6_pg_ue.pdf”。这是否意味着我必须在手机上存储该文件? – joacoleza

0

尝试使用这个插件的PhoneGap https://github.com/ti8m/DocumentHandler

下面是我如何整合它NG-点击。

$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"); 
    } 
} 
相关问题