在使用电子邮件时,如何打印当前由vue渲染的网页视图?正常的js函数window.print()打印为空。那么电子方式是什么呢?是否有可能在不转换为.pdf的情况下进行静默打印?
发布于 2021-02-25 15:18:20
要打印当前窗口,请使用以下代码
let win = BrowserWindow.getFocusedWindow(); 或
let win = BrowserWindow.getAllWindows()[0]; 要打印
win.webContents.print(options, (success, failureReason) => {
if (!success) console.log(failureReason);
console.log('Print Initiated');
});
}); full_code:
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');
});
}); https://stackoverflow.com/questions/54947775
复制相似问题