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

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

问题描述

我有一个从 PHP 服务器加载 URL 的 Electron 应用程序.该页面包含一个具有 PDF 源的 iFrame.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 代码类似于

And my js code is something like

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.

因此您可以像加载普通 HTML 文件一样加载 PDF 文件,PDF 查看器将自动显示.

So you can load PDF files just like normal HTML files, the PDF viewer will automatically show up.

例如在 BrowserWindow 中使用 .loadURL(...),在 <object> 中以及使用<webview>.

E.g. in BrowserWindow with .loadURL(…), in <iframes>, <object> and also with the, at the moment discouraged, <webview>.

PS:自 Electron 9 以来,不再需要在 BrowserWindow 中启用 plugins 属性.

PS: The need to enable the plugins property in the BrowserWindow or <webview> is no more needed since Electron 9.

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

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