电子PDF查看器 [英] Electron PDF viewer

查看:78
本文介绍了电子PDF查看器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Electron应用程序,可从PHP服务器加载URL.该页面包含一个具有PDF来源的iFrame.在普通的Web浏览器中,PDF页面似乎绝对可以,但是要求在Electron中下载.有帮助吗?

I have an Electron app that loads URL from PHP server. And the page contains an iFrame having a source to PDF. The PDF page seems absolutely ok in a normal web browser but asks for download in Electron. Any help?

我的html页面代码是

My codes for html page is

<h1>Hello World!</h1>
Some html content here...
<iframe src="http://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf" width="1200" height="800"></iframe>

我的js代码类似于

mainWindow = new BrowserWindow({width: 800, height: 600})
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))

app.on('ready', createWindow)

任何帮助都会非常有用...

Any help would be really greatful...

推荐答案

Electron已经附带集成的PDF查看器插件.但是,默认情况下停用插件.因此,您必须激活它们:

Electron is shipping already with an integrated PDF viewer plugin. However, plugins are deactivated by default. So you have to activate them:

对于 BrowserWindow ,您可以执行以下操作:

For a BrowserWindow you do:

let win = new BrowserWindow({
  webPreferences: {
    plugins: true
  }
})

对于 <webview> ,您可以这样做:

And for a <webview> you do it like this:

<webview src="example.com" plugins></webview>

这篇关于电子PDF查看器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆