Pdf.js: Setting up fake worker failed: "Cannot read property 'WorkerMessageHandler' of undefined"

Created on 11 Jun 2020  路  2Comments  路  Source: mozilla/pdf.js

Configuration:
Chrome version: 81.0.4044.129
OS: Ubuntu
PDF.js version: Using pdf-dist npm module(https://www.npmjs.com/package/pdfjs-dist)
Is a browser extension: No

Pdf file is: http://www.africau.edu/images/default/sample.pdf

Problem:
I am using a pdf-dist library, It was working correctly, but suddenly got an issue like the following picture
https://snipboard.io/A67H4J.jpg

Could you guys please provide any solution.

All 2 comments

PDF.js version: Using pdf-dist npm module(https://www.npmjs.com/package/pdfjs-dist)

Please provide the actual version number when opening an issue.

[...] but suddenly got an issue like the following picture

(Generally speaking, it's always easier/quicker for people if you actually attach screen-shots directly to the issue rather than linking to it.)

The screen-shot clearly shows that you haven't setup the PDF.js library correctly, based on the warning messages, since you should always ensure that the workerSrc property is set correctly such that the pdf.worker.js file can be found/loaded; basically you need to add a line looking something like the below (obviously with the path adjusted as necessary for your deployment) before calling pdfjsLib.getDocument(...) or doing anything else:

pdfjsLib.GlobalWorkerOptions.workerSrc = "../some/path/to/pdf.worker.js";

Finally, please note that this is a bug tracker rather than a support forum and that this issue is missing too many details to be actionable/valid; please also see https://github.com/mozilla/pdf.js/blob/master/.github/CONTRIBUTING.md (emphasis mine):

If you are developing a custom solution, first check the examples at https://github.com/mozilla/pdf.js#learning and search existing issues. If this does not help, please prepare a short well-documented example that demonstrates the problem and make it accessible online on your website, JS Bin, GitHub, etc. before opening a new issue or contacting us in the Matrix room -- keep in mind that just code snippets won't help us troubleshoot the problem.

pdfjs-dist: 2.2.228

Was this page helpful?
0 / 5 - 0 ratings

Related issues

liuzhen2008 picture liuzhen2008  路  4Comments

aaronshaf picture aaronshaf  路  3Comments

jigskpatel picture jigskpatel  路  3Comments

zerr0s picture zerr0s  路  3Comments

PeterNerlich picture PeterNerlich  路  3Comments