Describe the bug
See title. We are using Spring boot for the server and copy our files in the "public" folder. This means we changed angular.json/projects/PROJECT/architect/build/options/outputPath to ../resources/public and serve the "public" folder to the client.
We saw that the default lookup path for the worker is "../build/pdf.worker.js", which seems to not exist.
Do we need to copy the worker.js file to the correct location or do we set the worker.js location in pdfjs directly?
Version info
You don't need to do anything. If you PDF file is displayed, everything's fine.
I'm still trying to find out what these weird messages mean. I'm pretty sure it's a false positive. The default lookup path is also a puzzle. It shouldn't matter because the worker is imported by the angular.json (if you've followed my instructions, that is).
I'm keeping the ticket open. It's a good reminder to investigate the topic.
Hi guys.
I have the same problem. I thought pdfjs is doing the heavy load in a webworker for performance increasements. Currently when loading large PDFs the whole web application is blocked by this process which means I cannot interact with any of the other components outside pdfjs.
Also the browser brings up the message that a script is taking long time and ask me if I want to kill this script.
Shouldn't the webworker solve this problem? And at least the application should stay responsive?
Sounds like your PDFs are really large. How many megabytes, how many pages are we talking about?
BTW, it's an interesting theory that the "fake worker" stuff means pdf.js can't setup a worker thread. Maybe it's a hot trace. Thanks for the hint!
Sounds like your PDFs are really large. How many megabytes, how many pages are we talking about?
That is one of our test PDFs. Very heavy.
https://www.obwb.ca/library/okanagan-basin-waterscape-poster/
If I get https://github.com/mozilla/pdf.js/issues/7612 right, the pdf.worker.js must be in a file of its own (as opposed to being bundled with pdf.js). Otherwise it can't be run in a service worker thread.
You sample file is heavy indeed. My Firefox needed several minutes to open the file (using the native viewer). Adding Angular and a falsy webworker configuration probably doesn't make things better.
However, the PDF itself looks really nice. I guess someone (you?) has spent a lot of energy and enthusiasm on it. Awesome!
Finally, I've found an explanation what the fake worker is: https://www.codeproject.com/articles/568136/porting-and-extending-pdfjs-to-nodejs (scroll down to "Fake worker for web worker").
Good news: I've figured out how to use the service worker, and it improves the performance of the PDF viewer a lot. I'm publishing the new version this evening after adding the documentation.
Thanks for nudging into the right direction!
@Catscratch Completely off-topic - but when I opened your test document, this sentence caught my eye: "many say we should pay for the water based on how much we use". I can't believe it: you don't have water meters? They are so common in Europe I thought they're used everywhere. :)
Since version 1.5.0 you can use the service worker. Currently it's not configurable; it's always /assets/pdf-worker.js. So you have to rename the file pdf.worker-es5.js to support IE11.
Basically, that's the only thing blocking the issue from closing.
I don't know how to make it run.
I copied pdf.worker.js into /assets/ folder and tried both pdf-worker.js and pdf.worker.js, but I still get the warning: Setting up fake worker.
I also cloned https://github.com/stephanrauh/extended-pdf-viewer-showcase ran npm i and npm start and I still get the warning.
Is there another demo project I can use?
PS: with the new Version 1.5.0 I get the error "ERROR Error: "Uncaught (in promise): Error: Invalid pages rotation angle.".
I did a little research and it seems the error happened since 1.4.0.
In 1.3.1 there was no error
@Catscratch Completely off-topic - but when I opened your test document, this sentence caught my eye: "many say we should pay for the water based on how much we use". I can't believe it: you don't have water meters? They are so common in Europe I thought they're used everywhere. :)
Sorry to disappoint you, but it's not my document. It's just a random one from the internet that I use for testing. ;-)
@philippendrulat I'm still fighting with ES5 support for the PDF worker, so I didn't wan't to commit my code yesterday. Sorry for the inconvenience!
BTW: the pdf.worker.js file should be available as localhost:4200/assets/pdf.worker.js.
@philippendrulat Now it's landed. Please update to version 1.5.1. It fixes the rotation bug and allows you to define a custom path for the pdf worker. I needed that for IE11 support.
Updating https://github.com/stephanrauh/extended-pdf-viewer-showcase should give you a working example. It's the same as https://pdfviewer.net.
Thanks Stephan.
I don't get things running here.
I updated to 1.5.1 and addeddefaultOptions.workerSrc = './assets/pdf.worker-es5.js';to app.component.ts.Furthermore I checked that the asset is accessible through the browser. It is!
But I still get the "setting up fake worker" message. Any chance to debug into here?
I solved it.
I had to modify the scripts node in the angular.json to match the right js file. (es5 or not) to use the correct worker js.
Also I had toi add the asset to the angular build.
{
"glob": "pdf.worker-es5.js",
"input": "node_modules/ngx-extended-pdf-viewer/assets",
"output": "/assets/"
}
@Catscratch Correct! I tried to document these steps, but I'm not sure I've managed to finish that. If there's something missing in the doc, just tell me.
BTW, I'm glad it finally works on your PC!
@stephanrauh
Only difference is, I switched to the newer versions without "-es5" suffix.