电子:如何只在电子中静电印制html(div)的一部分?

我想要实现的是, 远程托pipe并正在我的电子应用程序中加载的网页将希望电子应用程序只打印一个特定的div元素。 我知道如果我使用webContents.print({silent:true})整个页面将无声打印。 但是我只想要一个特定的div发生同样的事情。 提前致谢。

这样做的一种方法是发送一个新的隐藏窗口,然后从那里打印。


main.js

 app.on('ready', function(){ mainWindow = new BrowserWindow({ width: 1080, height:720}) workerWindow = new BrowserWindow(); workerWindow.loadURL("file://" + __dirname + "/printerWindow.html"); workerWindow.hide(); }); // retransmit it to workerWindow ipcMain.on("printPDF", function(event, content){ workerWindow.webContents.send("printPDF", content); }); // when worker window is ready ipcMain.on("readyToPrintPDF", (event) => { workerWindow.webContents.print({silent: true}); }) 

controller.js

 // target the object you want to print and send it to the new window ipcRenderer.send("printPDF", div_to_be_targeted);