Silent printing in electron

前端 未结 3 857
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-06 10:35

I am currently building an electron app. I have a PDF on my local file system which I need to silently print out (on the default printer). I came across the node-printer library

3条回答
  •  难免孤独
    2021-02-06 11:12

    I recently published NPM package to print PDF files from Node.js and Electron. You can send a PDF file to the default printer or to a specific one. Works fine on Windows and Unix-like operating systems: https://github.com/artiebits/pdf-to-printer.

    It's easy to install, just (if using yarn):

    yarn add pdf-to-printer
    

    or (if using npm):

    npm install --save pdf-to-printer
    

    Then, to silently print the file to the default printer you do:

    import printer from "pdf-to-printer";
    
    printer
      .print("assets/pdf-sample.pdf")
      .then(console.log)
      .catch(console.error);
    

提交回复
热议问题