【发布时间】:2016-10-04 06:27:14
【问题描述】:
我正在尝试将我的网络转换为使用 ElectronJS 制作的应用
在我的网页中,我打印了一个带有条形码的 div。这工作得很好,但在 electronjs 中我无法做到这一点。
本来我会用这个功能
$scope.printDiv = function (divName) {
var printContents = document.getElementById(divName).innerHTML;
var popupWin = window.open('', '_blank', 'width=500,height=500');
popupWin.document.open();
popupWin.document.write('<html><head><link rel="stylesheet" type="text/css" href="styles/main.css" type=\"text/css\" media=\"print\" /></head><body onload="window.print()">' + printContents + '</body></html>');
popupWin.document.close();
}
用 electronjs
我不知道如何传递要打印的对象。
我也在尝试从我可以加载的内容生成 PDF。但 PDF 已损坏
var windowPrint = require('electron').remote.BrowserWindow;
var fs = require('fs');
var newWindow = new windowPrint({width: 800, height: 600, show: false});
console.log(newWindow);
newWindow.loadURL('http://github.com');
newWindow.show();
newWindow.webContents.print({silent: true, printBackground: true});
newWindow.webContents.printToPDF({printSelectionOnly : true, printBackground: true}, function (error, data) {
if (error) {
throw error;
}
console.log(error);
console.log(data);
fs.writeFile('print.pdf', function (data, error) {
if (error) {
throw error;
}
console.log(error);
console.log(data);
});
});
有一种简单的方法可以用 electronjs 打印一个 DIV 吗?
感谢您的阅读。
【问题讨论】:
-
github.com/electron/electron-api-demos 您可以创建一个不可见的空白窗口,从主进程接收信号(html 字符串),然后打印 pdf。
-
我见过,但这只是创建一个pdf?或者也发送打印命令?
-
抱歉回复晚了,你知道了吗?
-
我以前看过,但不能很好地打印 pdf,仍然得到损坏的文件。是否有任何关于在 electronjs 上打印和 pdf 的完整文档?谢谢你的回答
标签: javascript html angularjs node.js electron