【问题标题】:silent print is not working [ Electron JS ]静默打印不起作用 [Electron JS]
【发布时间】:2019-08-01 05:26:19
【问题描述】:

我尝试使用 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); 
   });    
});

【问题讨论】:

    标签: javascript node.js printing electron


    【解决方案1】:

    我之前也遇到过类似的问题,我就是这样解决的:

    1. 确保您的电子在全球范围内被Electron --version降级
    2. 如果版本号不是3.1.11,说明你的electron还在旧版本下运行。您需要在全球范围内重新安装/降级它。我正在使用 npm,所以命令行应该看起来像 npm install electron@version --g
    3. 测试代码是否在无静默模式下运行win.webContents.print({ silent: false})

    我的问题是 Electron 没有在全球范围内降级(即使 package.json 中的版本号也是正确的)。我希望这对你有帮助,我花了几天时间测试 Electron 版本的打印功能。希望 Electron 7 能在今年年底全面发布。

    【讨论】:

      猜你喜欢
      • 2021-08-11
      • 1970-01-01
      • 2018-06-16
      • 2018-09-14
      • 1970-01-01
      • 2021-01-13
      • 1970-01-01
      • 2020-07-05
      • 2013-11-08
      相关资源
      最近更新 更多