opening pdf files in electron

2020-04-14 04:47发布

问题:

I need to build an app where the user can open PDF files within the app -- i.e. not by opening a new browser window. I would need to implement a back button and possibly some overlays over the PDF. Does anyone know if there's a good way to do this in Electron?

回答1:

If you're OK with UI provided by chrome PDF extension you can use it from electron.

See this question

const {app, BrowserWindow} = require('electron')

app.once('ready', () => {
  let win = new BrowserWindow({
    webPreferences: {
      plugins: true
    }
  })
  win.loadURL(__dirname + '/test.pdf')
})

Note, that electron's native PDF support is available only since version 1.6.4. Before that you can use electron-pdf-window



回答2:

You should checkout gerhardberger's electron-pdf-window