No PDFJS.workerSrc specified

前端 未结 5 1196
借酒劲吻你
借酒劲吻你 2021-01-07 23:18

Trying to use PDF JS in a local Apache server and receiving the following error in console:

Uncaught Error: No PDFJS.workerSrc specified

Th

5条回答
  •  花落未央
    2021-01-07 23:51

    I had a similar error and I fixed it by specifying the pdf.worker.js explicitly at the end of the 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  or  ????   ********
      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';
    }
    

提交回复
热议问题