2016-04-29 85 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"); 
    } 
} 
相關問題