如何将页面设置从ElectronJS中的渲染器进程动态传递到主进程?
我想将页面设置动态地从渲染器进程传递到主进程。基本上,主要流程中的printToPDF函数应采用pageSettings对象并进行相应的打印。目的是动态设置页面宽度。
简短的代码如下。但这不起作用。
//Sending from Renderer Process
ipc.send("readyToPrint", page_settings);
//Receiving at Main Process
ipc.on("readyToPrint", (event, page_settings) => {
const pdfPath = path.join(os.tmpdir(), 'print.pdf');
/* Default Settings
var pageSettings = {
'marginsType': 1,
'printBackground': true,
'pageSize': {
"height": 297000,
"width": 72000
}
}
*/
var pageSettings = page_settings;
workerWindow.webContents.printToPDF(pageSettings, function (error, data) {
if (error) throw error
fs.writeFile(pdfPath, data, function (error) {
if (error) {
throw error
}
shell.openItem(pdfPath);
})
})
});