电子版本:2.0.7
作业系统:Ubuntu 16.04
节点版本:8.11.1
电子版
let win = new BrowserWindow({width: 302, height: 793,show:false});
win.once('ready-to-show', () => win.hide());
fs.writeFile(path.join(__dirname,'/print.txt'), "Test Print From the app",function(){
win.loadURL(`file://${path.join(__dirname,'/print.txt')}`);
win.webContents.on('did-finish-load', () => {
let printersInfo = win.webContents.getPrinters();
let printer = printersInfo.filter(printer => printer.isDefault === true)[0];
win.webContents.print({silent: true, printBackground: true, deviceName : printer.name},() => {
win = null;
});
});
})
Run Code Online (Sandbox Code Playgroud)
win.webContents.print(silent: true, printBackground: true, deviceName : "POS-1") 产生如下图所示的异常数据:
win.webContents.print(silent: false, printBackground: true, deviceName : "POS-1") 产生异常数据并重叠文件文本,如下图所示:
我也尝试过html文件,但它也会产生相同的输出。
如果我写有silent : true和没有,deviceName那么它什么也不会产生。
let …Run Code Online (Sandbox Code Playgroud)