javascript - Electron:如何以pdf格式打印所有html内容
问题描述
我在我的第一个项目中使用 Electron,我必须从我的 html 打印一个 PDF 文件。
现在我的代码中有什么:
ipc.on('print-to-pdf', event => {
const pdfPath = path.join(os.tmpdir(), 'temp_pdf.pdf')
const win = BrowserWindow.fromWebContents(event.sender)
win.webContents.printToPDF({marginsType: 1, pageSize:'Tabloid'}, (error, data) => {
if (error) return console.log(error.message)
fs.writeFile(pdfPath, data, err => {
if (err) return console.log(err.message)
shell.openExternal('file://' + pdfPath)
})
})
})
but when my app create .pdf file, the content is sliced in the second page.
Like that:
[Error pdf][1]
maybe it depends on the setting of the page size:
win.webContents.printToPDF({marginsType: 1, pageSize:'Tabloid'}, (error, data) => {
if (error) return console.log(error.message)
我该如何解决?
解决方案
我解决了在我的css中添加这个:
@media print {
body {
overflow: visible !important;
}
}
现在pdf已经完成,显示所有页面
推荐阅读
- sql-server - SSRS 自动导出每个参数值的报告
- asynchronous - Flutter - 有没有办法将事件从我的 API 填充到 TableCalendar 的“事件”属性
- css - Bootstrap 中自定义 CSS 的正确路径
- javascript - 您可以在浏览器上安全地使用 String.trim() 还是应该添加 shim?
- python - 需要了解 `yield` 如何为 `pytest` 工作?
- python - 使用 Flask 链接到网站中的另一个页面
- arduino - 有理由不直接打印 uint64_t 吗?
- r - 只在 RStudio 中阅读自制的 r 包
- c++ - 无法让变量相互交互(C++)
- crystal-reports - 在水晶报告中总结来自两个不同组的详细信息