6

I am previewing a pdf file using Mozilla's PDF.js. The code I use for preview is the following:

function previewPDF(url,canvasName){

    PDFJS.workerSrc = 'js/pdfJS/pdf.worker.js';

    PDFJS.getDocument(url).then(function getPdf(pdf) {
        pdf.getPage(1).then(function getPage(page) {
            var scale = 1.5;
            var viewport = page.getViewport(scale);

            var canvas = document.getElementById(canvasName);
            var context = canvas.getContext('2d');
            canvas.height = viewport.height;
            canvas.width = viewport.width;

            var renderContext = {
                canvasContext: context,
                viewport: viewport
            };
            page.render(renderContext);
        });
    });
}

However, now I need only a print button with which I can print the pdf file. I have tried numerous times with window.print() but it does not seem to work. Do you have any ideas how I can I do that?

Thank you in advance!!!

Ivan Ivanov
  • 243
  • 4
  • 15
  • there are some answers here on [this post](https://stackoverflow.com/questions/14401965/printing-pdf-using-pdf-js), which may be useful to you. – Ajay Jadhav Dec 07 '16 at 10:31
  • Does this answer your question? [Printing PDF using pdf.js](https://stackoverflow.com/questions/14401965/printing-pdf-using-pdf-js) – Rohan Ashik Feb 15 '20 at 10:52

0 Answers0