javascript - 使用 electron.js 打印当前的 vue-view
问题描述
使用electron时如何打印vue渲染的当前网页视图?正常的 js 函数window.print()
打印为空。那么什么是电子方式呢?是否有可能在不转换为 .pdf 的情况下进行静默打印?
解决方案
要打印当前窗口,请使用以下代码
let win = BrowserWindow.getFocusedWindow();
或者
let win = BrowserWindow.getAllWindows()[0];
打印
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');
});
});
推荐阅读
- r - 如何将 for 循环内的基本 R Plot 更改为 ggplot?
- reactjs - React 本机 flatlist 倒序
- parsing - 使用 attoparsec 在 Haskell 中重载字符串的问题
- python - 网络浏览器打开位置python
- ios - 验证 MYAPP.app 的代码签名失败
- apollo - [网络错误]:错误:使用 Apollo Link State 将结果写入存储以进行查询时出错
- python - 如何在 SOAP 库 zeep 中解决过去的错误?
- postman - 邮递员:测试无法引用预期的变量
- java - JSF - 从数据表中删除时出现空指针异常
- c# - 我可以使用 Telerik Document Processing 阅读 PDF 内容吗?