opening pdf files in electron

10,237

Solution 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

Solution 2

You should checkout gerhardberger's electron-pdf-window

Share:
10,237
David J.
Author by

David J.

Updated on June 15, 2022

Comments

  • David J.
    David J. almost 2 years

    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?

  • leonheess
    leonheess over 5 years
    I did exactly that but it still starts a download instead of displaying it
  • leonheess
    leonheess almost 5 years
    See this question if you are using Electron 3.0.0 or later: stackoverflow.com/q/52844135/7910454