Skip to content Skip to sidebar Skip to footer

No Pdfjs.workersrc Specified

Trying to use PDF JS in a local Apache server and receiving the following error in console: Uncaught Error: No PDFJS.workerSrc specified This is very weird, because I'm following

Solution 1:

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 && typeofdocument !== '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';
}

Solution 2:

Include compatibility.js to fix the "Uncaught Error: No PDFJS.workerSrc specified" error on IE11.

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

<scriptsrc="compatibility.js"></script><scriptsrc="pdf.js"></script>

compatibility.js implements any missing functionality required by PDFJS.

Note: It should be loaded before PDFJS, not after.

Solution 3:

Specify psd.worker.js file path in your page where you want to use the pdf.js file (viewer.html in case you are using viewer.html come with distribution bundle) like this. It work for me.

<script>PDFJS.workerSrc ='path to psd.worker.js';

Solution 4:

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

if (!PDFJS.workerSrc && typeofdocument !== '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';
}

Solution 5:

Go to pdf.js

search function getWorkerSrc()

replace this lines

pdfjsFilePath = "YOUR_PATH_TO_JS_FILE/pdf.worker.js";
if (pdfjsFilePath) {
  return pdfjsFilePath;
} 

Post a Comment for "No Pdfjs.workersrc Specified"