我正在尝试创建一个用于打印字母大小 PDF 的 Electron JS 应用程序。
这是我的打印代码片段:
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 上遇到过同样的事情?
原文由 Grig Dodon 发布,翻译遵循 CC BY-SA 4.0 许可协议
如果您已经拥有 pdf 文件或在打印“我假设它是”之前保存了 pdf,那么您可以获取文件位置,然后您可以使用外部进程使用
child_process
进行打印。您可以使用
lp command
或 PDFtoPrinter for windows我希望它有所帮助。
编辑: 您也可以使用 SumatraPDF for windows https://github.com/sumatrapdfreader/sumatrapdf