【发布时间】:2018-09-14 00:03:26
【问题描述】:
我正在尝试创建一个用于打印字母大小 PDF 的 Electron JS 应用程序。
这是我的打印代码sn-p:
win = new BrowserWindow({
width: 378,
height: 566,
show: true,
webPreferences: {
webSecurity: false,
plugins: true
}
});
// load PDF
win.loadURL('file://' + __dirname + '/header1_X_BTR.pdf');
// if pdf is loaded start printing
win.webContents.on('did-finish-load', () => {
win.webContents.print({silent: true, printBackground:true});
});
我的问题是:如果我有print({silent:true}),我的打印机会打印一个空白页。如果我有print({silent:false}),打印机的打印方式与屏幕截图相同,带有标题、控件等。
我需要 PDF 内容的静默打印,但我好几天都做不了。有人对 Electron 有过同样的经历吗?
【问题讨论】:
-
请将您的复制代码上传到
git存储库。通过复制,我可以更好地帮助您。 -
@Noseratio Heyho,因为 Electronjs 在 Nodejs 之上是非常错误的东西,我建议尝试"how to print PDF in Nodejs app" 的答案。您必须在后台生成新的子进程并尝试使用外部工具(当然,您必须检查平台,例如 darwin vs win)。
-
@boldnik,我想我在my answer 中介绍了这些选项。
标签: javascript node.js pdf printing electron