window.print()用电子生成PDF

问题描述 投票:2回答:1

我有一个Angular应用程序,您可以在其中计算一些内容,最后生成一个结果页面,可以通过window.print()打印/导出为pdf。这也完全按预期工作。

但我们现在还用Electron构建了这个应用程序的桌面版本。如果我想在Electron应用程序中打印/导出结果页面,则会打开Windows打印弹出窗口(compare this image),我只能选择打印机,但没有选项可以将其导出为pdf。

有没有办法仍然使用window.print()并添加将其导出为pdf的可能性(基本上像web中的window.print()版本)?

javascript angular pdf pdf-generation electron
1个回答
0
投票

在ElectronJS中,您可以使用printToPDF而不是客户端js功能,因为electronJS可以直接访问文件系统。

以下是API的示例实现。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.