一直在开发使用Electron 4和angular 7的POS桌面应用程序。需要实现发票/收据的打印。 Electron具有打印当前页面或创建PDF并进行打印的功能。但是,我需要传递原始数据进行打印,因为我们已经为打印纸预定义了模板。 请提前使用我们可以使用的模块来实现此目的。
答案 0 :(得分:0)
我已将 node-thermal-printer 库用于接受 ESC / POS命令
的任何打印机的热敏打印。这两种打印机都可以使用,例如LAN或USB。
我已将此库用于带有Electron的 EPSON 和 Everycom 热敏打印机,并且运行良好。
https://www.npmjs.com/package/node-thermal-printer。
希望这对您有所帮助。
答案 1 :(得分:0)
请尝试使用电子正装打印机包装。 npm i electron-pos-printer
。查看documentation
演示
// In the main process
const {PosPrinter} = require("electron-pos-printer");
// or in render process
const {PosPrinter} = require('electron').remote.require("electron-pos-printer");
// each object in the data array accounts for a row or line
const print_data = [
{
type: 'image',
path: path.join(__dirname, 'assets/banner.png'), // file path
position: 'center', // position of image: 'left' | 'center' | 'right'
width: 60, // width of image in px; default: auto
height: 60, // width of image in px; default: 50 or '50px'
},
{type: 'text', value: 'Sample text', style: 'text-align:center;font-weight: bold'},
{type: 'text', value: 'Another text', style: 'color: #fff'},
{type 'barCode', value: 'HB4587896', height: 12, width: 1, fontsize: 9},
{type 'qrCode', value: 'https://google.com', height: 55, width: 55, style: 'margin: 10 20px 20 20px'}
];
// returns promise<any>
PosPrinter.print(print_data, {
printerName: 'XP-80C',
preview: false,
width: '170px', // width of content body
margin: '0 0 0 0', // margin of content body
copies: 1, // The number of copies to print
})
.then(() => {
// some code ...
})
.catch((error) => {
console.error(error);
});