【发布时间】:2022-06-10 18:41:52
【问题描述】:
有人从事 electron.js pdf 导出工作吗? 我需要在单击按钮时将文件导出为 pdf,我使用了“.webContents.printToPDF”,但“'did-finish-load'”对我不起作用。
电子版 - 16 节点版本 - 14
electron.ipcMain.on('exportPdf', (event, path) => {
console.log("data-above000");
// Use default printing options
console.log("data-above");
// const pdfPath = ph.join(__dirname, 'docs/new.pdf');
mainWindow.webContents.printToPDF(options).then(data => {
console.log("data", data);
fs.writeFile(path, data, (error) => {
if (error) throw error
console.log(`Wrote PDF successfully to ${path}`)
})
}).catch(error => {
console.log(`Failed to write PDF to ${path}: `, error)
})
console.log("data-below");
})
【问题讨论】:
-
你为什么用
did-finish-load'你用loadURL还是什么?给我们一些代码 -
你到底想导出什么为 pdf 当前窗口?
-
你能提供它的代码和你得到的错误吗?
-
请提供足够的代码,以便其他人更好地理解或重现问题。
标签: javascript html reactjs electron