小编Pro*_*osh的帖子

如何使用电子webContents.print([options],[callback])打印html / text文件?


电子版本:2.0.7

作业系统:Ubuntu 16.04

节点版本:8.11.1


电子版

let win = new BrowserWindow({width: 302, height: 793,show:false});
win.once('ready-to-show', () => win.hide());
    fs.writeFile(path.join(__dirname,'/print.txt'), "Test Print From the app",function(){
        win.loadURL(`file://${path.join(__dirname,'/print.txt')}`);
        win.webContents.on('did-finish-load', () => {
            let printersInfo = win.webContents.getPrinters();
            let printer = printersInfo.filter(printer => printer.isDefault === true)[0];
            win.webContents.print({silent: true, printBackground: true, deviceName : printer.name},() => {
                win = null;
            });
        });
    })
Run Code Online (Sandbox Code Playgroud)

win.webContents.print(silent: true, printBackground: true, deviceName : "POS-1") 产生如下图所示的异常数据:

在此处输入图片说明

win.webContents.print(silent: false, printBackground: true, deviceName : "POS-1") 产生异常数据并重叠文件文本,如下图所示:

在此处输入图片说明

我也尝试过html文件,但它也会产生相同的输出。

如果我写有silent : true和没有,deviceName那么它什么也不会产生。

let …
Run Code Online (Sandbox Code Playgroud)

javascript printing node.js electron

5
推荐指数
1
解决办法
1071
查看次数

标签 统计

electron ×1

javascript ×1

node.js ×1

printing ×1