Electronic PDF Viewer

I have an Electron application that downloads a URL from a PHP server. And the page contains an iFrame with a source for PDF. The PDF page looks completely normal in a normal web browser, but asks to download to Electron. Any help?

My html page codes

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

And my js code is 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 wonderful ...

+5
source share
2 answers

Electron already comes with a built-in PDF viewer plugin. However, plugins are deactivated by default. Therefore, you must activate them:

For BrowserWindow you do:

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

And for <webview> you do it like this:

 <webview src="example.com" plugins></webview> 
+8
source

You will need https://github.com/gerhardberger/electron-pdf-window

Example:

 const { app } = require('electron') const PDFWindow = require('electron-pdf-window') app.on('ready', () => { const win = new PDFWindow({ width: 800, height: 600 }) win.loadURL('http://mozilla.imtqy.com/pdf.js/web/compressed.tracemonkey-pldi-09.pdf') 

})

+1
source

Source: https://habr.com/ru/post/1266334/


All Articles