Javascript 电子应用程序的原始打印
我想创建一个支持原始打印的电子应用程序 任何关于我可以选择的图书馆或道路的建议都将不胜感激。我做了一些研究,但似乎没有什么是最新的。我想得到所有可用的打印机,并得到默认的打印机和打印它Javascript 电子应用程序的原始打印,javascript,printing,electron,network-printers,epos,Javascript,Printing,Electron,Network Printers,Epos,我想创建一个支持原始打印的电子应用程序 任何关于我可以选择的图书馆或道路的建议都将不胜感激。我做了一些研究,但似乎没有什么是最新的。我想得到所有可用的打印机,并得到默认的打印机和打印它 我有一个小例子,你可以告诉我,这将是可怕的 在尝试了几种方法和软件包之后,我通过以下方式获得了成功: 共享打印机 使用node cmd将文件副本发送到共享打印机 注意,我只在Windows上使用和测试过 yarn add node-cmd 范例 const fs = window.require('fs')
我有一个小例子,你可以告诉我,这将是可怕的 在尝试了几种方法和软件包之后,我通过以下方式获得了成功:
- 共享打印机
- 使用node cmd将文件副本发送到共享打印机
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 )
}
})
你找到解决办法了吗?