stephanrauh / ngx-extended-pdf-viewer

A full-blown PDF viewer for Angular 16, 17, and beyond
https://pdfviewer.net
Apache License 2.0
450 stars 168 forks source link

loading wrong Version of pdf.worker-...js files #2271

Closed Faegen closed 2 months ago

Faegen commented 2 months ago

Hello,

I use Angular and have updated to the version "ngx-extended-pdf-viewer": "19.6.1". Since then I have the problem. First, when loading the PDF viewer, the files pdf-4.0.854.min.mjs and viewer-4.0.854.min.mjs are loaded correctly. But then the file pdf.worker-4.0.851.min.mjs is loaded and not found.

Which is correct, as it points to a different version (4.0.851) than is present in the ng-modules folder.

Does anyone know the problem? Before the update to the new version it worked fine.

stephanrauh commented 2 months ago

Maybe it's a caching problem. I've just deleted the node_modules folder of my showcase, ran npm install, and everything works like charm:

image
Faegen commented 2 months ago

Hello,

I have also cleared node_modules and tested the whole thing, but unfortunately it makes no difference. I also deleted the complete browser cache, but unfortunately that didn't help either.

I updated to 19.7.1 today. Now I have the same problem, only with version 4.0.859.

devtt

Perhaps the problem is due to the fact that I integrate the PDF viewer as a web component. So I load it separately from another main component. Although I don't understand why this should have anything to do with the version number. Because it worked with the first version

The main component that loads the PDF viewer, has the same packed installed. Since the assets path are copied in the angular.json: { "glob": "**/*", "input": "node_modules/ngx-extended-pdf-viewer/assets/", "output": "/assets/" }

stephanrauh commented 2 months ago

Now that's really strange. I suggest you switch to the non-minified version of pdf.js because it simplifies debugging. Set the attribute [minifiedJSLibraries]="false".

Debug the pdf-4.0.xxx.mjs file. Scan for static get workerSrc() and const worker = new Worker(this.#generateTrustedURL(workerSrc), {. That's were the worker file is loaded. The filename should match the version number of the pdf-4.0.xxx.mjs file. If it doesn't, I hope the two breakpoints help you to find out what's going wrong. Also check the console window. It prints the version number of pdf.js. This version number should be 4.0.859 if you're using ngx-extended-pdf-viewer 19.7.1.

Note that the console message often mentions a slightly outdated version of ngx-extended-pdf-viewer. That's a consequence of how I build the version, and it's something I want to fix soon. Don't be confused by that.

Faegen commented 2 months ago

Thanks for your Input.

I tried the whole thing, but it still loads the wrong one. And in the debug, these values are also in the variables. logs1 logs2

I can get the component to run on its own. So when I call up the closed component locally, the files are loaded correctly.

When I load the component embedded, it tries to load the wrong versions. But I don't understand why...

Faegen commented 2 months ago

I have now tried the whole thing in another browser in which I have never opened the pdfViewer. I have the same problem there, so it's probably not a cache problem either

stephanrauh commented 2 months ago

I'm puzzled. What happens if you start fresh? I.e. if you create a new project with ng new and add the PDF viewer with ng add ngx-extended-pdf-viewer? This takes only five minutes and tells us if there's something wrong your project or with the library itself.

Faegen commented 2 months ago

As stated above. The PDF viewer works on its own. I think the problem is that I have a parent component that loads the single component with the viewer.

childc

The reason why I also load the package in the main component is only because the path for the assets refers to the main component and not to the child component.

So all files are in the node-modules folder of the main component. The versions that are there are also correct. Only when the child component is called is an attempt made to load the pdfViewer. And then the wrong version is set in the structure of the libary.

When debugging, I find at the breakpoint you showed me (const worker = new Worker(this.#generateTrustedURL(workerSrc)) that the wrong version is in "workerSrc" from the beginning. However, the versions that are set in pdf-4.0.859.mjs always look correct. e.g.: const version = '4.0.859';

The very first time I installed the package, it worked. There it always tried to load the 4.0.581 and at that time the version was correct

stephanrauh commented 2 months ago

Where does the version number "851" come from? I've scanned the entire project, I can't find it anywhere. Does it hide in a file of your project?

stephanrauh commented 2 months ago

Any news?

Faegen commented 2 months ago

Hello

I have tried the whole thing again, but the problem persists. I can't find an explanation for it my "solution" was. rename the files of the new version so that they have the same name as version 851. This is not a good solution ... but at the moment it works...