首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未指定PDFJS.workerSrc

未指定PDFJS.workerSrc
EN

Stack Overflow用户
提问于 2014-09-29 13:27:04
回答 5查看 28.1K关注 0票数 16

尝试在本地Apache服务器中使用PDF并在控制台中接收以下错误:

代码语言:javascript
复制
Uncaught Error: No PDFJS.workerSrc specified

这是非常奇怪的,因为我遵循示例中http://mozilla.github.io/pdf.js/examples/指定的所有内容。

在我的主文件夹中,我有一个名为file.pdf的示例文件,我只是想显示它。我是通过使用带有file参数的iframe来做到这一点的:

代码语言:javascript
复制
<iframe src="./web/viewer.html?file=http://localhost:99/PDF/arquivo.pdf" width="1800px" height="900px" />

现在我正在尝试使用JavaScript API来显示它。我想做的是:

代码语言:javascript
复制
<!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,我会收到:

代码语言:javascript
复制
GET http://localhost:99/PDF/build/pdf.worker.worker.js 404 (Not Found)

因为它以编程方式包括pdf.worker.js.

通过我在这里发布的示例代码,我收到了一个日志和一个错误:

代码语言:javascript
复制
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文档。

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2014-10-10 02:29:43

我有一个类似的错误,我通过在pdf.worker.js的末尾显式地指定pdf.js来修正它。

代码语言:javascript
复制
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';
}
票数 19
EN

Stack Overflow用户

发布于 2016-04-21 02:09:45

包含compatibility.js以修复IE11上的“未指定的错误:没有指定的PDFJS.workerSrc”错误。

https://github.com/mozilla/pdf.js/blob/master/src/shared/compatibility.js

代码语言:javascript
复制
<script src="compatibility.js"></script>
<script src="pdf.js"></script>

compatibility.js实现了PDFJS所需的任何缺少的功能。

注意:它应该在PDFJS之前加载,而不是在PDFJS之后加载。

票数 11
EN

Stack Overflow用户

发布于 2015-05-19 11:31:25

在您的页面中指定psd.worker.js文件路径,您希望在其中使用pdf.js文件(如果您使用的是viewer.html附带发行包,则使用viewer.html),如下所示。对我来说很管用。

代码语言:javascript
复制
<script>
    PDFJS.workerSrc ='path to psd.worker.js';

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26101071

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档