pdf.js在requirejs中使用,workerSrc和getDocument浏览器总报错?

在main.js中引入pdf.js
'pdfJs': 'plugins/pdfjs/build/pdf',
在页面中
define(['pdfJs'], function (pdfjs) {})
下面是使用
pdfjs.workerSrc =STATIC_CTX + '/static/scripts/plugins/pdfjs/build/pdf.worker.js';
var loadingTask = pdfjs.getDocument({
url: src,
cMapUrl: STATIC_CTX + '/static/scripts/plugins/pdfjs/web/cmaps/',
cMapPacked: true
});
loadingTask.promise.then(function(pdf) {
console.log('PDF loaded');

        var pageNumber = 1;
        pdf.getPage(pageNumber).then(function(page) {
               console.log('Page loaded');

               var scale = 1.5;
               var viewport = page.getViewport(scale);
               var canvas = document.getElementById('the-canvas');
               var context = canvas.getContext('2d');
               canvas.height = viewport.height;
               canvas.width = viewport.width;
               var renderContext = {
                            canvasContext: context,
                             viewport: viewport
                };
                var renderTask = page.render(renderContext);
                           renderTask.then(function () {
                                    console.log('Page rendered');
                             });
   });

最后运行在浏览器中就报错
Uncaught TypeError: Cannot read property 'getDocument' of undefined

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐