Uncaught ReferenceError: PDFJS is not defined when initialising PDF.JS

不羁的心 提交于 2019-12-08 03:28:09

问题


I am trying to install PDF.JS in a CMS of sorts where the outer skeleton of the page is built for me, including the reference to jQuery (which is still version 1.10.2).

I have tried adding these two lines:

<script src="https://mozilla.github.io/pdf.js/build/pdf.js"></script>
<script src="https://mozilla.github.io/pdf.js/build/pdf.worker.js"></script>

And the running this command:

<script>
    PDFJS.getDocument('/loc/testpdf.pdf');
</script>

But they return this error:

VM485:14 Uncaught ReferenceError: PDFJS is not defined
at eval (eval at <anonymous> (jquery.js?v=910.1:4), <anonymous>:14:1)
at eval (<anonymous>)
at jquery.js?v=910.1:4
at Function.globalEval (jquery.js?v=910.1:4)
at init.domManip (jquery.js?v=910.1:5)
at init.append (jquery.js?v=910.1:5)
at init.<anonymous> (jquery.js?v=910.1:5)
at Function.access (jquery.js?v=910.1:4)
at init.html (jquery.js?v=910.1:5)

I have been going round for a couple of hours trying to figure out what's wrong. Have I initialised it correctly or do we think it's related to the outdated version of jQuery?

Thanks


回答1:


try run the script after page loaded;

$(document).ready(function () {
    PDFJS.getDocument('/loc/testpdf.pdf');
})


来源:https://stackoverflow.com/questions/48647838/uncaught-referenceerror-pdfjs-is-not-defined-when-initialising-pdf-js

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!