I just started using the monocle reader and tried using a pdf i downloaded before it has roughly 800 pages and 25mb file size, the problem now is that monocle returns with this error
TypeError: Cannot read property 'onFirstPageOfBook' of null
Resource interpreted as Document but transferred with MIME type application/pdf
If i use a 1 page pdf it works fine.
This is my code:
<script type="text/javascript">
var bookData = {
getComponents: function () {
return [
'coolresume.pdf',
'content1.html'
];
},
getContents: function () {
return [
{title: "Chapter 1", src: 'coolresume.pdf'},
{title: "Chapter 2", src: 'content1.html'}
]
},
getComponent: function (componentId) {
return {url:componentId};
},
getMetaData: function(key) {
return {
title: "Test document",
creator: "Aron Woost"
}[key];
}
}
Monocle.Events.listen(
window,
'load',
function () {
window.reader = Monocle.Reader('reader', bookData);
}
);
</script>
This is were i got my sample PDF, this also works fine for when the same PDF is converted to EPUB
PDFs may not be officially supported by monocle js: https://groups.google.com/forum/#!searchin/monocle-js/pdf/monocle-js/0ue1t243JLg/hgOPIQaramQJ
However some PDFs work and some don't. I've tracking the ones that don't down to the monocle js source code, lines 3555, 3556, 3557:
Monocle.Events.listen(frame, 'load', onDocumentReady);
Monocle.Events.listen(frame, 'load', onDocumentLoad);
frame.contentWindow.location.replace(url);
...using PDF as a source, a url
value is sent to the frame.contentWindow.location.replace
function, but with some PDFs the load
event is not firing, therefore the previously attached functions do not execute and the script stalls with a blank page, but other PDFs load fine.
Also, when I run the monocle HTML page through the theseus debugger, the failing PDFs also load just fine.
Another point, monocle js is loading the PDFs in an embed tag. The same embed tag code loaded independently of monocle js loads just fine. And the ones that work load 2 pages, both embed tags with the same PDF url. The ones that don't work only get one embed tag implemented but not all the monocle id's are there.
It may be related to file size. I was not able to load a PDF at 555K, but 412K and lower loaded fine.
It's a nasty hack, but this loads the PDFs that won't otherwise:
//Monocle.Events.listen(frame, 'load', onDocumentReady);
//Monocle.Events.listen(frame, 'load', onDocumentLoad);
frame.contentWindow.location.replace(url);
onDocumentReady();
onDocumentLoad();