stephanrauh / ngx-extended-pdf-viewer

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

Cannot deploy the latest version 19.0.x #2065

Closed lucho78 closed 7 months ago

lucho78 commented 7 months ago

Hi, I've tried the latest version of the module. It works fine with 'ng serve but when I compile it the pdf is not shown. I did not change the procedure since a while and it works fine with the version 18.

What should I change in the build to make it work? Thanks Luc

stephanrauh commented 7 months ago

Bonsoir Luc, maybe it's the same problem as #2066. The base library now uses .mjs files instead of .js files. Sometimes this requires extra configuration.

If that's not the problem, can you see something in the console or the network tab?

lucho78 commented 7 months ago

Thanks for your reply Stephan but there is something weird on my side: Here the network traces on my browser with the version 19.0.4 image In the dom: image

I've checked and my assets folder contains all the files needed image

Why the file "viewer-3.xx.min.js" is correctly downloaded in the version 18.1.x image In the dom: image

Any suggestions? Thanks a lot Cheers Luc

stephanrauh commented 7 months ago

I'm confused. The preview tab in your screenshot seems to indicate the JavaScript file is downloaded, but you say it's not?

The only idea crossing my mind is that the file ending has changed to *.mjs. JavaScript interprets mjs files differently than *.js files, so that's nothing I can change. Maybe your server needs additional configuration to ship this file as a JavaScript file.

lucho78 commented 7 months ago

Sorry my previous message was not very clear. Basically the file pdf-4.xx.min.mjs is correctly downloaded. But the file viewer-4.0.730.mjs is not included in the DOM so not downloaded on the local machine.

For your information, I'm doing the test with a local server (local tomcat embedded in Spring boot)

stephanrauh commented 7 months ago

I see. Please add a breakpoint at the loadViewer() method. Is it ever called?

image

Until recently, I always found the method by opening the file ngx-extended-pdf-viewer.mjs, but it seems in production mode you have to find the method in the main.js.

lucho78 commented 7 months ago

Hi Stephan, First thanks a lot for your support. I really appreciate :-)

image It seems that the method "script.onload" is never triggered for me. The code on the line 400348 is never called. So the method "loadViewer" is never called. I've checked: the file "http://localhost:8080/assets/pdf-4.0.730.min.mjs" exists and it's accessible from the browser.

Any idea? Thanks Luc

stephanrauh commented 7 months ago

No idea. If the first <script> is added properly to the DOM and if it triggers loading the pdf.js file, and if that's successful, it's hard to imagine why onload() is not called. That's a basic JavaScript functionality.

Did you try different browsers? And did you try [minifiedJSLibrary]="false"? Maybe it has something to do with a virus scanner or an ad blocker (but that's a far shot).

stephanrauh commented 7 months ago

You could also try to update to version 19.0.6. It fixes the viewer if it's running in an iFrame. Maybe the same bug fix helps you, too.

lucho78 commented 7 months ago

I've tried with the version 19.0.6 with the parameter [minifiedJSLibrary]="false". I get the same behavior with chrome.

With firefox, I get the following exception: image Same behavior if [minifiedJSLibrary]="true"...

Any other ideas? Thanks a lot Luc

stephanrauh commented 7 months ago

Yes, I'm back to my first theory. You must configure Spring Boot correctly. It seems it isn't familiar with *.mjs files. Something along these lines. I didn't test them, they may be buggy, but you get the idea:

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**/*.mjs")
                     ...
    }

    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer.mediaType("mjs", new MediaType("text", "javascript"));
    }
}
lucho78 commented 7 months ago

Super thanks a lot for your great support. The following config on Spring boot solves my issue. @Override public void configureContentNegotiation(ContentNegotiationConfigurer configurer) { configurer.mediaType("mjs", new MediaType("text", "javascript")); }