Trying to use PDF JS in a local Apache server and receiving the following error in console:
Uncaught Error: No PDFJS.workerSrc specified
Th
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';
}