2017-05-19 12 views
0

thisを使用して、私のSPAにPDFを表示したいと思います。angular-pdfjs-viewerが動作していません

私は1つの例を構築しようとしましたが、動作しませんでした。

angular.module('app', ['pdfjsViewer']); 

angular.module('app').controller('AppCtrl', function ($scope, $http, $timeout) { 
    var url = 'http://example.com/file.pdf'; 

    $scope.pdf = { 
     src: url, // get pdf source from a URL that points to a pdf 
     data: null // get pdf source from raw data of a pdf 
    }; 

    getPdfAsArrayBuffer(url).then(function (response) { 
     $scope.pdf.data = new Uint8Array(response.data); 
    }, function (err) { 
     console.log('failed to get pdf as binary:', err); 
    }); 

    function getPdfAsArrayBuffer (url) { 
     return $http.get(url, { 
      responseType: 'arraybuffer', 
      headers: { 
       'foo': 'bar' 
      } 
     }); 
    } 
}); 

ができます:エラーがある場合、私は本当に知らない、多分それは私のcontrolerにある私のPDFはhttp://example.com/file.pdf

である。この例では、このPlunker

http://plnkr.co/edit/nZAjYr?p=preview

を見て誰でも私を助けてくれますか?

答えて

1

あなたのコントローラは、次のようになります。

angular.module('app').controller('AppCtrl', function ($scope, $sce, $http, $timeout) { 
    var url = 'http://example.com/file.pdf'; 
    PDFJS.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js' 

    $scope.pdf = { 
     src: $sce.trustAsResourceUrl(url), // get pdf source from a URL that points to a pdf 
     data: null // get pdf source from raw data of a pdf 
    }; 
}); 

は、不要なコードを削除し、詳細については、コンソールを確認してください。

関連する問題