i'm trying to convert my web into an app made in ElectronJS
in my web i print a div with a barcode. this works pretty fine, but in electronjs i can't reach this.
originally i'd use this function
$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();
}
with electronjs
i don't know how to pass the object to print.
also i'm trying to generate a PDF from content that i can load. but the PDF's are corrupted
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);
});
});
there's a simple way to print a DIV with electronjs?
thank you for reading.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…