Javascript 使用electron.js打印当前vue视图

Javascript 使用electron.js打印当前vue视图,javascript,vue.js,electron,Javascript,Vue.js,Electron,使用electron时,如何打印vue呈现的当前网页视图?正常的js函数window.print()打印为空。那么电子的方式是什么呢?是否可以在不转换为.pdf的情况下进行静默打印?要打印当前窗口,请使用下面的代码 let win = BrowserWindow.getFocusedWindow(); 或 印刷 win.webContents.print(options, (success, failureReason) => { if (!success

使用electron时,如何打印vue呈现的当前网页视图?正常的js函数
window.print()
打印为空。那么电子的方式是什么呢?是否可以在不转换为.pdf的情况下进行静默打印?

要打印当前窗口,请使用下面的代码

let win = BrowserWindow.getFocusedWindow(); 

印刷

  win.webContents.print(options, (success, failureReason) => { 
            if (!success) console.log(failureReason); 
      
            console.log('Print Initiated'); 
        }); 
    }); 
完整代码:

const electron = require('electron') 
const BrowserWindow = electron.remote.BrowserWindow; 
  
var current = document.getElementById('current');  
var options = { 
    silent: false, 
    printBackground: true, 
    color: false, 
    landscape: false, 
    pagesPerSheet: 1, 
    collate: false, 
    copies: 1, 
    header: 'Header of the Page', 
    footer: 'Footer of the Page'
} 
  
current.addEventListener('click', (event) => { 
    let win = BrowserWindow.getFocusedWindow(); 
    
  
    win.webContents.print(options, (success, failureReason) => { 
        if (!success) console.log(failureReason); 
  
        console.log('Print Initiated'); 
    }); 
}); 
const electron = require('electron') 
const BrowserWindow = electron.remote.BrowserWindow; 
  
var current = document.getElementById('current');  
var options = { 
    silent: false, 
    printBackground: true, 
    color: false, 
    landscape: false, 
    pagesPerSheet: 1, 
    collate: false, 
    copies: 1, 
    header: 'Header of the Page', 
    footer: 'Footer of the Page'
} 
  
current.addEventListener('click', (event) => { 
    let win = BrowserWindow.getFocusedWindow(); 
    
  
    win.webContents.print(options, (success, failureReason) => { 
        if (!success) console.log(failureReason); 
  
        console.log('Print Initiated'); 
    }); 
});