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

前端 未结 6 1681
离开以前
离开以前 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:11

    This is actually a lot easier using a dataURI, because you can just call print on the returned window object.

    // file is a File object, this will also take a blob
    const dataUrl = window.URL.createObjectURL(file);
    
    // Open the window
    const pdfWindow = window.open(dataUrl);
    
    // Call print on it
    pdfWindow.print();
    

    This opens the pdf in a new tab and then pops the print dialog up.

提交回复
热议问题