在电子中打印iframe显示保存对话框而不是打印对话框

时间:2018-01-06 22:16:05

标签: javascript pdf iframe printing electron

我在分支上有一个示例应用:https://github.com/EricG-Personal/electron_pdfkit_test/tree/feature/with_iframe

这是一个非常简单的基于反应的应用程序,在启动时,动态创建PDF并将其加载到iframe中。

我有一个包含PDF内容的iframe。我尝试用以下内容打印这个iframe:

iframeloaded()
{
    console.log( "iframe loaded - printing" );

    // window.frames[0].focus();
    // window.frames[0].print();

    var myWindow = remote.getCurrentWindow();

    myWindow.webContents.print();
}

但是,会出现一个保存对话框,而不是预期的打印对话框。

有没有办法让打印对话框出现?

保存的PDF确实包含正确的内容。

我在最新版本的OS X上使用最新版本的电子。

1 个答案:

答案 0 :(得分:0)

仅在最新版本的电子版中支持显示PDF(我认为大约为1.7),您需要启用插件。

要为BrowserWindow执行此操作,您需要设置plugins:true

const window = new BrowserWindow({
    webPreferences: {
        plugins: true
    }
})

我不确定这是否适用于iframe但您可以尝试使用<webview>代码并确保enable plugins

<webview src="https://www.github.com/" plugins></webview>