我试图使用Electron JS打印收据,但无提示打印无效。
在github中有人建议我降级到3.1.11。我没有用。它仍然显示打印对话框。
打印当前页面:
let win = BrowserWindow.getFocusedWindow();
win.webContents.print({silent: true});
我试图将内容加载到其他窗口中也没有用
let win=new BrowserWindow({
width:450,
height:750,
show: false
});
win.loadURL(`file://${__dirname}/receipt.html?data=${data}`);
win.webContents.on('did-finish-load', () => {
console.log("content loaded" ;
// Use default printing options
win.webContents.print({ silent: true },(status)=>{
console.log("print-status",status);
});
});
最佳答案
我之前也遇到过类似的问题,这就是我如何解决的问题:
Electron --version
全局降级npm install electron@version --g
win.webContents.print({ silent: false})
我的问题是Electron没有在全局范围内降级(即使package.json中的版本号是正确的)。希望对您有所帮助,我已经花了几天时间测试 Electron 版的打印功能。希望,Electron 7将于今年年底全面发布。
关于javascript - 静默打印不起作用[Electron JS],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57302311/