使用离子framwork在android中创建pdf阅读器

时间:2017-02-02 13:13:51

标签: android angularjs cordova pdf ionic-framework

使用pdf.js在离子中创建pdf阅读器它可以完美地用于app文件夹pdf文件,但是外部应用程序文件夹无法运行我的代码。

PDFJS.workerSrc = '/lib/pdf/pdf.worker.js';
var filename     = decodeURIComponent($stateParams.pdffile);
alert(filename);

$cordovaFile.readAsArrayBuffer(cordova.file.externalDataDirectory+"book_folder/",filename).then(function(arraybuffer) {

    var uInt8Arr = new Uint8Array(arraybuffer);

    PDFJS.getDocument(uInt8Arr).then(function(pdfFromRaw) {
        pdfFromRaw.getPage(1).then(function(page) {
        var scale = 1.5;
        var viewport = page.getViewport(scale);

        var canvas = document.getElementById('pdf');
        var context = canvas.getContext('2d');
        canvas.height = viewport.height;
        canvas.width = viewport.width;

        var renderContext = {
        canvasContext: context,
        viewport: viewport
        };
        page.render(renderContext);
    });
});

0 个答案:

没有答案