Print a pdf with javascript or jquery

前端 未结 2 373
长情又很酷
长情又很酷 2021-01-16 13:59

I need to print a .pdf file (I generate it with jasperReport and I save it on a server) when I click on a print.gif button. Now I found this solution that works for Firefox

相关标签:
2条回答
  • 2021-01-16 14:42

    Create a iframe in html:

    <iframe id="pdf-iframe">
    

    Then change the src of that iframe and on load, print it.

    $('#pdf-iframe').attr("src", pdf_url).load(function(){
        document.getElementById('pdf-iframe').contentWindow.print();
    });
    
    0 讨论(0)
  • 2021-01-16 14:55

    I believe the Problem is that the content is not loaded yet? I had the same issue in IE8. I had to save the document, reopen it, print, and close the window again.

    0 讨论(0)
提交回复
热议问题