No PDFJS.workerSrc specified

前端 未结 5 1249
借酒劲吻你
借酒劲吻你 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-08 00:15

    I added below code in end of pdf.js and working fine

    if (!PDFJS.workerSrc && typeof document !== 'undefined') {
      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');
      })();
      PDFJS.workerSrc = 'pdf.worker.js';
    }
    

提交回复
热议问题