PDFJS does not recover from a PDF Worker loading failure
See original GitHub issueConfiguration:
- 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:
- Open this JSFIddle.
- Click on
Load Existing
, and it should render the pdf. ( You can click this many times ) - Click on
Load Missing
, and it should display an error message. - 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:
- Created 2 years ago
- Reactions:1
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 toGlobalWorkerOptions.workerPort
before callingpdfjsLib.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 thepdf.worker.js
file and use a blob-URL in thenew Worker(...)
call.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.