How to send a pdf file directly to the printer using JavaScript?

前端 未结 6 1679
离开以前
离开以前 2020-12-02 08:42

How to send a PDF file directly to the printer using JavaScript?

I found two answers in a forum:



        
6条回答
  •  攒了一身酷
    2020-12-02 09:05

    I think this Library of JavaScript might Help you:

    It's called Print.js

    First Include

    
    
    

    It's basic usage is to call printJS() and just pass in a PDF document url: printJS('docs/PrintJS.pdf')

    What I did was something like this, this will also show "Loading...." if PDF document is too large.

    
    

    However keep in mind that:

    Firefox currently doesn't allow printing PDF documents using iframes. There is an open bug in Mozilla's website about this. When using Firefox, Print.js will open the PDF file into a new tab.

提交回复
热议问题