mozilla / pdf.js

PDF Reader in JavaScript
https://mozilla.github.io/pdf.js/
Apache License 2.0
48.51k stars 9.98k forks source link

Instructions for using with Cordova #6455

Closed mixmastamyk closed 9 years ago

mixmastamyk commented 9 years ago

Hi,

Haven't found any instructions for using with Cordova, primarily on recent Android. Here is my code so far, but it does nothing. The canvas exists.

Can anyone help? Didn't find solutions in the other bugs here.

            console.log('pdf time:....');
            PDFJS.disableWorker = true;
            PDFJS.getDocument(cached).then(function(pdf) {
                // Using promise to fetch the page
                pdf.getPage(1).then(function(page) {
                    var scale = 1;
                    var viewport = page.getViewport(scale);

                    // Prepare canvas using PDF page dimensions
                    var canvas = document.getElementById('pdfview');
                    var context = canvas.getContext('2d');
                    canvas.height = viewport.height;
                    canvas.width = viewport.width;

                    var renderContext = {
                        canvasContext: context,
                        viewport: viewport
                    };
                    page.render(renderContext);
                });
            });
timvandermeij commented 9 years ago

I don't think anyone here has experience with Cordova. The code fragment looks good, so probably the issue is elsewhere in your code. You need workers for good performance. compatibility.js does not necessarily have to be included unless you need support for legacy browsers/systems. If there are errors, they are usually found in the console. For local files you will need a server, see also #5548.

Closing as answered for now. If there are specific bugs in PDF.js (i.e., not related to your custom implementation with Cordova), please open a new issue with steps to reproduce.

yurydelendik commented 8 years ago

See also http://stackoverflow.com/a/34027997/1765767