【问题标题】:Raw printing with Electron app使用 Electron 应用程序进行原始打印
【发布时间】:2017-10-08 23:48:26
【问题描述】:

我想创建一个支持原始打印的电子应用。

任何关于我可以采用的库或路径的建议都将不胜感激。我做了一些研究,但似乎没有什么是最新的。我想获取所有可用的打印机并获取默认打印机并使用它进行打印。

我有一个小例子可以给我看,它会很棒!

【问题讨论】:

  • 您找到解决方案了吗?

标签: javascript printing electron network-printers epos


【解决方案1】:

在尝试了几种方法和包之后,我能够通过以下方式取得成功:

  • 共享打印机
  • 使用 node-cmd 将文件副本发送到共享打印机。

注意,我只在 Windows 上使用和测试过。

yarn add node-cmd

例子

const fs = window.require('fs')
const path = window.require('path')
const cmd = window.require('node-cmd')

//Save the raw output to the filesystem
const filePath = path.join(__dirname, 'rawprint.prn') //or wherever you want to save it

//Create a command to copy the file to the shared printer path (e.g. \\localhost\DPD ). Make sure that var is sanitised first! 
const command = `COPY /B "${filePath}" "${pathToSharedPrinter}"`

cmd.get( command, (err, data, stderr) => {

    if ( !err ) {
        console.log('Success!')
    } else {
        console.log( err.message )
    }

})

【讨论】:

    猜你喜欢
    • 2015-11-23
    • 1970-01-01
    • 2017-08-31
    • 1970-01-01
    • 2016-02-20
    • 2016-05-05
    • 1970-01-01
    • 2021-07-30
    • 2018-02-16
    相关资源
    最近更新 更多