我正在尝试通过使用参数来控制如何打开pdf来在iframe中打开pdf文件。它们在网站上效果很好,但是在 Electron 上却不起作用:pdf在iframe内打开,但是'view = fitH'指定的缩放级别在 Electron 上似乎不起作用。有什么办法也可以使参数在 Electron 中起作用吗?这是我正在使用的代码。
<iframe src='./res/test.pdf#page=1&toolbar=0&statusbar=0&messages=0&navpanes=0&scrollbar=0&view=fitH' frameborder="0" style="width:72.5%;height:95%;position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);"></iframe>
更新:
我将尝试提供有关我要执行的操作的更多详细信息。我正在从macOS Sierra构建应用程序,最终目标是要有一个适用于Windows的本地应用程序,当没有互联网连接时,可以使用该应用程序代替在线应用程序。我正在使用以下命令来构建应用程序:
electron-packager ./ --platform=all --arch=all --overwrite --asar
但是,pdf并不符合iframe的宽度,而是缩小了,如下图所示:
The actual result - you can see that the pdf is zoomed out a lot
我将尝试从Windows构建应用程序,看看是否可以解决问题。
最佳答案
我看到它的工作方式与浏览器中的工作方式相同
main.js
const {app, BrowserWindow} = require('electron')
app.once('ready', () => {
let win = new BrowserWindow({
webPreferences: {
plugins: true
}
})
win.loadURL(`${__dirname}/pdfargs.html`)
})
pdfargs.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Page Title</title>
</head>
<body>
<iframe src='./res/test.pdf#page=1&toolbar=0&statusbar=0&messages=0&navpanes=0&scrollbar=0&view=fitH' frameborder="0" style="width:72.5%;height:95%;position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);"></iframe>
</body>
</html>
关于electron - 用于打开在 Electron 中不起作用的pdf文件的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50349788/