PDFJS is not defined
AnsweredI'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 expandbox-preview.js
pdf.min.js
pdf_viewer.min.js
pdf_viewer.min.css
pdf.worker.min.js
exif.min.jsNot 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.
-
Hi , Our fix has been merged, and is scheduled for the next release. https://github.com/box/box-content-preview/pull/561
-
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.
Please sign in to leave a comment.
Comments
9 comments