Skip to main content

I'm trying to use box-preview element for a PDF file but my UI is showing an error message saying PDFJS is not defined.

 

I'm using box's CDN to get the js and css file. I've tried both 1.20.1 and 1.19.1 version.

 

Here's the code i'm using to load the view

 

            var preview = new Box.Preview();
preview.show('', '', {
container: '.preview-container',
showDownload: true
});

Box's server is sending proper response, but UI rendering is failing.

 


Hello a1626!


 


Can you please share some more about your project? What are you using to load Preview's CSS and JS? Are you using any frontend frameworks?

Also, does this example work with your token and file ID? https://codepen.io/box-platform/pen/rmZdjm (please comment out the collection option).


 


Thanks,


Tony



Hi Tonyjin

 

My project is an angularjs project.

I've updated the pen with my access token and file id. https://codepen.io/a1626/pen/rYRgoV

It seems to be working fine in the pen.

 

Update

It works if i load all the files from cdn directly ie also import


Click to expand

box-preview.js
pdf.min.js
pdf_viewer.min.js
pdf_viewer.min.css
pdf.worker.min.js
exif.min.js



Not sure if leaving one or two imports will do the trick or not.

 

Only including pdf.min.js throws new error cannot read property 'prototype' of undefined.

 



Thanks for the report. Are you using RequireJS? We've seen similar issues in the past, there seems to be some sort of issue with how we load some of our dependencies and how it interacts with other JS loaders.



Yes, we are using requirejs. So, is there any other way to fix this issue other than importing more than required files. Anyways, we would prefer not to load it via CDN.

 



I'd suggest continuing to use your workaround for now, but I definitely agree this isn't optimal. We'll take a closer look and fix this.



Hi tonijin,

 

Is there any progress or update regarding this fix, we have a similar issue using requirejs in v1.25. This could be a critical deal breaker for us.

 

Thanks.



Hi , Our fix has been merged, and is scheduled for the next release. https://github.com/box/box-content-preview/pull/561



That is absolute wonderful news, thanks 



This error still occurs.. for us it was when the preview was loading and a user was scrolling over the container.

 

I'm guessing there is a scroll event listener (or other mouse event listener) that's firing something before PDFJS is ready.  

 

We are using the libraries from the CDN since we are using Angular for our framework.

(would be wonderful if there was an Angular library in the works!)

We're rendering many instances of the previewer in a list view.

The error is usually triggered when the user scrolls through the list prior to the previewer fully loading.

 

I worked around it by checking for an error and retrying the load. 

Here's the code in case anyone else can find it useful.

 

 

BOX_r82yua037xycm7lr72bx5kgj3cuh174n.png

 

BOX_a27vo3o6p2els4z91akam6rcrg4n8667.png



Reply