【发布时间】:2017-06-23 18:15:29
【问题描述】:
我想使用this 在我的 SPA 中显示 PDF。
我尝试构建一个示例,但没有成功。看看这个 Plunker
http://plnkr.co/edit/nZAjYr?p=preview
在此示例中,我的 pdf 位于 http://example.com/file.pdf
我真的不知道错误在哪里,可能是在我的控制器中:
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'
}
});
}
});
谁能帮帮我?
【问题讨论】: