PDFTron not loading PDF files in production mode on custom domain

WebViewer Version: 8.7.0

Do you have an issue with a specific file(s)? NO
Can you reproduce using one of our samples or online demos? NO
Are you using the WebViewer server? NO
Does the issue only happen on certain browsers? NO
Is your issue related to a front-end framework? YES
Is your issue related to annotations? NO

Please give a brief summary of your issue:
(Think of this as an email subject)
I am trying to embed the WebViewer into an Angular app, which is deployed in AWS on a custom domain. It works when ran locally both in development mode and in production mode. Only when I deploy to AWS in prod mode do these errors appear.

The error is as follows:
Uncaught (in promise) r {name: ‘WorkerError’, stack: ‘WorkerError: The worker has encountered an error\n …lib/core/webviewer-core.min.js:132:473)’, message: ‘The worker has encountered an error’, userMessage: ‘error.EmsWorkerError’}

webviewer-core.min.js:214 Failed to find PDF worker files. This project is not set up to work with PDF files.

Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)

We are loading the WebViewer in a simple Angular component, very similar to the PDFTron sample Angular project. There are no errors in the network tab on the browser developer tools. All PDFTron files are being found.

Please provide a link to a minimal sample where the issue is reproducible:

ngAfterViewInit(): void {
this.documentLoaded$ = new Subject();

    WebViewer({
        path: './lib',
        fullAPI: true,
    }, this.viewer.nativeElement).then(instance => {
        this.wvInstance = instance;
        const { documentViewer } = instance.Core;
        instance.UI.loadDocument('form.pdf');
        this.coreControlsEvent.emit(instance.UI.LayoutMode.Single);

        documentViewer.addEventListener('documentLoaded', async () => {
            this.documentLoaded$.next();
        });
    });
}

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hello,

Could you please double-check the network requests again for the workers? I suspect the request is ok but what it got might have been an HTML error page instead. If that is the case, please ensure your mimetypes are set up in your deployment environment.

Can you also confirm that the path provided to WebViewer is also correct and that the files are reachable?

Hi Andy,
I have checked the network requests and they all return content, no html error pages.
For the mimetypes, some of these were set wrong in AWS s3 I corrected those and refreshed but still no luck.
Any other thoughts?

I think I’ve narrowed it down to the blob:https://domain.com/ call in the network tab. Locally (blob://http://localhost:8000) returns 200 and previewing the file shows minified javascript. On AWS this file returns 200 and previewing it just shows random boxes and Chinese characters.

On AWS…

Locally…

Hm, that doesn’t seem right. It seems like AWS might be serving the file incorrectly. Perhaps you could double-check the mime types around that as well. vue.js - AWS Cloudfront serving javascript modules as wrong MIME type( "Text/Plain") - Stack Overflow

This isn’t a file that we can see in the S3 bucket. It seems to be a file that the Pdfworker.js generates and serves back to the browser as a blob with a randomly generated name each time. The browser thinks the file is applicaton/javascript but the contents when accessing though AWS are not javascript. Not too sure if serving this from AWS is the issue or the file isn’t being decoded properly. Locally I can see a call to decode.min.js. This isn’t present on AWS.

On AWS…


Notice the referer is blank and there is no call to decode.min.js

Locally…


Notice here the referer is Pdfworker.js and there is a call to decode.min.js on the left

Hm, that’s odd. Perhaps you could export a HAR file for us to take a look at? If you want more confidentiality, you could submit a ticket here: PDFTron Systems Inc. | Form.