I'm running a grails app on local host (which i know there's an issue with pdf.js and local file system) and instead of using a file: url which i know would fail i'm passing in a typed javascript array and it's still failing. To be correct it's not telling me anything but "Warning: Setting up fake worker." and then it does nothing.
this.base64ToBinary = function(dataURI) {
var BASE64_MARKER = ';base64,';
var base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length;
var base64 = dataURI.substring(base64Index);
var raw = window.atob(base64);
var rawLength = raw.length;
var array = new Uint8Array(new ArrayBuffer(rawLength));
for(i = 0; i < rawLength; i++) {
array[i] = raw.charCodeAt(i);
}
return array;
};
PDFJS.disableWorker = true; // due to CORS
// I convert some base64 data to binary data here which comes back correctly
var data = utilities.base64ToBinary(result);
PDFJS.getDocument(data).then(function (pdf) {
//nothing console logs or reaches here
console.log(pdf);
}).catch(function(error){
//no error message is logged either
console.log("Error occurred", error);
});
I'm wondering if I just don't have it set up correctly? Can I use this library purely on the client side by just including pdf.js or do I need to include viewer.js too? and also i noticed compatibility file... the set up isn't very clear and this example http://jsfiddle.net/epistemex/LUNaJ/ works and mine doesn't and I'm not understanding the difference. Also if I use the url supplied in that example it also says the same thing.
I've made this issue more comprehensive with some updates please let me know if you can shed some light. Nothing hits the error function either and all I see in my console is what you see in the screenshot.
We cannot help until we will see the complete example and have a way to reproduce the issue locally. Please read https://github.com/mozilla/pdf.js/blob/master/CONTRIBUTING.md and provide more information as requested.
@yurydelendik How am i supposed to get that to you the fiddle example works but the exact same code doesn't work on my environment... thus i can't repro it for you... the best i can think of is that i can do a google hangout or screenhero with you to show you.
Could you at least give me some possibilities?
Just guessing (from experience):
what is pdf.worker.js?
I'm using the latest release. Also is there some documentation around disableWorker/workerSrc?
pdf.worker.js is main file that performs PDF parsing (outside page main thread). When disableWorker=true it will be loaded into main page automatically (from workerSrc location) and block UI for PDF parsing needs. See https://github.com/mozilla/pdf.js/blob/master/src/display/api.js#L65
ahhh ok i figured out what the issue is... you should probably make a note of this in the documentation or make it clear. So if you don't specify workerSrc you try to figure out what it is by using the last script tag in the head of the application to go and load it but what if the app is grails or serves up some combined file uri? You cannot also reliably assume that that the last script tag would have the correct source. If you want to do this the right way you'd need to loop through all the script tags in the head looking for pdf.js in each src and then use the correct source instead of grabbing the last one.
I personally don't know anything about grails. We have workerSrc configurable for those cases.
you'd need to loop through all the script tags
That will not help in case when pdf.js
name is changed or part of the combined file.
Closing as invalid.
"That will not help in case when pdf.js name is changed or part of the combined file." true but aside from my own issues using grails you should just loop through them anyways to make the standard method more accurate. It's full of holes.
Most helpful comment
"That will not help in case when pdf.js name is changed or part of the combined file." true but aside from my own issues using grails you should just loop through them anyways to make the standard method more accurate. It's full of holes.