我正在尝试将我的网络转换为ElectronJS制作的应用程序
在我的网页中,我打印了一个带有条形码的div。这个很好用,但在电子产品中我无法达到这一点。
最初我会使用这个函数
$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();
}
使用电子产品
我不知道如何把这件东西传递给印刷商。
此外,我正在尝试从我可以加载的内容生成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);
});
});
有一种简单的方法可以用电子设备打印DIV吗?
感谢您的阅读。
4条答案
按热度按时间js81xvg61#
在加载完成之前,您已经打印了此页。
我的方法:1.创建一个主窗口和一个(看不见的)工作窗口
2、mainWindow.html
3、worker.html
hs1rzwqc2#
谢谢,也可以使用print()进行打印
(事件将相应地重新命名)
gpfsuwkq3#
这可能有点晚了,但对于其他想要以电子格式打印div的人,我建议您使用Range对象选择您的div,然后使用主进程打印pdf,并将printSelectionOnly设置为True。
JS正在渲染进程中:
主流程中的JS:
91zkwejq4#
在加载完成之前,您已经打印了此页。
我的方法:1.创建一个主窗口和一个(看不见的)工作窗口
2、mainWindow.html
3、worker.html