Printing PDF using pdf.js

前端 未结 3 619
庸人自扰
庸人自扰 2020-12-10 17:23

I am embedding a single page PDF in a page using pdf.js and I want to be able to print just the PDF, not the whole HTML page.

Is this possible?

3条回答
  •  悲哀的现实
    2020-12-10 17:59

    We can put following code at the end of viewer.js file which will automatically print pdf:

    (function () {
        function printWhenReady() {
            try{
                if (PDFViewerApplication.initialized) {
                    window.print();
                }
                else {
                    window.setTimeout(printWhenReady, 3000);
                }
            }catch(ex){
                window.setTimeout(printWhenReady, 3000);
            }
        };
    
        printWhenReady();
    })();
    

提交回复
热议问题