首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用electron.js打印当前vue-视图

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

Stack Overflow用户
提问于 2019-03-01 23:34:20
回答 1查看 274关注 0票数 2

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

EN

回答 1

Stack Overflow用户

发布于 2021-02-25 15:18:20

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

代码语言:javascript
复制
let win = BrowserWindow.getFocusedWindow(); 

代码语言:javascript
复制
 let win = BrowserWindow.getAllWindows()[0]; 

要打印

代码语言:javascript
复制
  win.webContents.print(options, (success, failureReason) => { 
            if (!success) console.log(failureReason); 
      
            console.log('Print Initiated'); 
        }); 
    }); 

full_code:

代码语言:javascript
复制
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'); 
    }); 
}); 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54947775

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档