尝试在本地Apache服务器中使用PDF并在控制台中接收以下错误:
Uncaught Error: No PDFJS.workerSrc specified这是非常奇怪的,因为我遵循示例中http://mozilla.github.io/pdf.js/examples/指定的所有内容。
在我的主文件夹中,我有一个名为file.pdf的示例文件,我只是想显示它。我是通过使用带有file参数的iframe来做到这一点的:
<iframe src="./web/viewer.html?file=http://localhost:99/PDF/arquivo.pdf" width="1800px" height="900px" />现在我正在尝试使用JavaScript API来显示它。我想做的是:
<!DOCTYPE html>
<html>
<head>
<script src="./build/pdf.js" type="text/javascript"></script>
<script type="text/javascript">
PDFJS.getDocument('arquivo.pdf').then(function(pdf) {
// Here I use it
})
</script>
</head>
<body>
</body>
</html>如果我尝试手动包含pdf.worker.js,我会收到:
GET http://localhost:99/PDF/build/pdf.worker.worker.js 404 (Not Found)因为它以编程方式包括pdf.worker.js.
通过我在这里发布的示例代码,我收到了一个日志和一个错误:
Error: No PDFJS.workerSrc specified pdf.js:249
at error (http://localhost:99/PDF/build/pdf.js:251:15)
at Object.WorkerTransport (http://localhost:99/PDF/build/pdf.js:2305:9)
at Object.getDocument (http://localhost:99/PDF/build/pdf.js:1805:15)
at http://localhost:99/PDF/:6:10 pdf.js:251
Warning: Unsupported feature "unknown" pdf.js:234
Uncaught Error: No PDFJS.workerSrc specified我需要手动指定pdf.worker.js?吗?拜托,我能想办法解决这个问题吗?
非常感谢!
(*) -我可以看到缺乏良好的内容和解释很好的PDF.JS文档。
发布于 2014-10-10 02:29:43
我有一个类似的错误,我通过在pdf.worker.js的末尾显式地指定pdf.js来修正它。
if (!PDFJS.workerSrc && typeof document !== 'undefined') {
// workerSrc is not set -- using last script url to define default location
****** I have no clue what the code below hope to accomplish ********
****** How can it locate the script container by assuming it ********
****** always would be at the end of <body> or <head> ???? ********
PDFJS.workerSrc = (function () {
'use strict';
var scriptTagContainer = document.body ||
document.getElementsByTagName('head')[0];
var pdfjsSrc = scriptTagContainer.lastChild.src;
return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
})();
****** Here I just hardcode the location of the needed file *********
****** This is the part that makes it work. *********
****** Obviously, tailor this to the same path of pdf.js *********
PDFJS.workerSrc = '/static/js/pdf.worker.js';
}发布于 2016-04-21 02:09:45
包含compatibility.js以修复IE11上的“未指定的错误:没有指定的PDFJS.workerSrc”错误。
https://github.com/mozilla/pdf.js/blob/master/src/shared/compatibility.js
<script src="compatibility.js"></script>
<script src="pdf.js"></script>compatibility.js实现了PDFJS所需的任何缺少的功能。
注意:它应该在PDFJS之前加载,而不是在PDFJS之后加载。
发布于 2015-05-19 11:31:25
在您的页面中指定psd.worker.js文件路径,您希望在其中使用pdf.js文件(如果您使用的是viewer.html附带发行包,则使用viewer.html),如下所示。对我来说很管用。
<script>
PDFJS.workerSrc ='path to psd.worker.js';
https://stackoverflow.com/questions/26101071
复制相似问题