question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PDFJS does not recover from a PDF Worker loading failure

See original GitHub issue

Configuration:

  • Web browser and its version: Chrome 96.0.4664.45
  • Operating system and its version: Windows 10.0.19044.1387
  • PDF.js version: 2.10.377

Steps to reproduce the problem:

  1. Open this JSFIddle.
  2. Click on Load Existing, and it should render the pdf. ( You can click this many times )
  3. Click on Load Missing, and it should display an error message.
  4. Try clicking on Load Existing again, and it should no longer render the pdf, and it should display the error.

What is the expected behavior?

PDFJs should support PDF Worker loading failures, since it could also happen in a situation of bad signal. It should not be required to reload the whole page.

The problem is caused by those [1, 2] codeblocks.

Currently we have implemented a workaround by overriding the PDFWorker’s _setupFakeWorker:

pdfjs.PDFWorker.prototype._setupFakeWorker = function () {
    this._readyCapability.reject(new Error('Worker could not be loaded!'));
};

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
Snuffleupaguscommented, Dec 2, 2021

There should be a work-around available, which is that you manually load the pdf.worker.js file and create a Worker first.[1] Once that’s been successfully loaded, assign it to GlobalWorkerOptions.workerPort before calling pdfjsLib.getDocument.

As far as I understand, that should provide a work-around using existing code and not require us to (further) complicate the worker-loading/initialization code in the API itself.


[1] You could e.g. use either new Worker(/* path to the pdf.worker.js file */) or manually load the pdf.worker.js file and use a blob-URL in the new Worker(...) call.

0reactions
skrthebosscommented, Dec 1, 2021

It depends, f.e. in an Angular application ( which is a Singe Page Application ), it is likely that the app is loaded correctly. Then when you navigate through specific routes/pages where the PDF is rendered, it can occurr that the network is not available for one short moment, but is available again as soon as you switch page again. The application should not break only for the short absence of the network.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pdf.js not loading pdf file - Stack Overflow
but that didn't work either. My console log states two things: 1) Loading failed for the with source “file:///pdf.js/build/pdf ...
Read more >
PDF.js Express Viewer Events | Documentation
Although WebViewer can recover from most loading errors, you may want to show a custom error message, submit a log to an API,...
Read more >
JSDoc: Source: display/api.js
By default PDF.js attempts to load PDFs in chunks. * The default value is `false`. * @property {boolean} [disableAutoFetch] - Disable pre-fetching of...
Read more >
JSDoc: Module: pdfjsLib
The default value is DEFAULT_RANGE_CHUNK_SIZE. worker, PDFWorker, <optional>, The worker that will be used for loading and parsing the PDF data.
Read more >
Rendering PDF pages with PDF.js and Vue - rossta.net
This code is split out into a separate file, pdf.worker.js , which will ... loading PDF.js to render an entire PDF document (without...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found