0

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>

the monocle

This is were i got my sample PDF, this also works fine for when the same PDF is converted to EPUB

PDF URL

magicianiam
  • 1,474
  • 7
  • 33
  • 70
  • Can you provide a link to the Pfg in question. Maybe it is not entirely valid. – mkl May 29 '14 at 13:45
  • @mkl what do you mean by pfg? – magicianiam May 29 '14 at 14:09
  • It's an innocent typo, mkl clearly meant "PDF" . That said: are you sure this is not a limit in Monocle? Can you successfully read other PDFs, 800 pages or >25 MB or both? – Jongware May 29 '14 at 16:29
  • @Jongware is right. It sometimes is funny to see what smart phone typing helpers do to your text. – mkl May 29 '14 at 22:20
  • @mkl oh sorry about that. :D, anyway i have yet to try using smaller pdf's but i wanted to try and covert it to EPUB format but all converter i found so far failed at converting such a file, will try to find some small book pdf's to try, since i wanted to use this as an online pdf reader. – magicianiam May 30 '14 at 03:24
  • Maybe error is document related. If it fails for conversion then try to reproduce the errors with other pdfs. You can then tell us what exactly is causing it. – user568109 Jun 03 '14 at 05:18
  • @user568109 the pdf's when converted to other format works fine, but if use the pdf themselves then i get the same error – magicianiam Jun 03 '14 at 06:46
  • Is the PDF in question protected by any chance? – Fraser Jun 08 '14 at 23:44

1 Answers1

1

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();
bloodyKnuckles
  • 11,551
  • 3
  • 29
  • 37