https://github.com/gerhardberger/electron-pdf-window
view PDF files in electron browser windows
https://github.com/gerhardberger/electron-pdf-window
Last synced: 10 days ago
JSON representation
view PDF files in electron browser windows
- Host: GitHub
- URL: https://github.com/gerhardberger/electron-pdf-window
- Owner: gerhardberger
- License: mit
- Created: 2016-10-25T22:22:27.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-03-09T19:17:11.000Z (about 3 years ago)
- Last Synced: 2025-03-28T19:09:45.891Z (17 days ago)
- Language: JavaScript
- Size: 2.3 MB
- Stars: 283
- Watchers: 6
- Forks: 92
- Open Issues: 29
-
Metadata Files:
- Readme: README.md
- License: license
Awesome Lists containing this project
- awesome-electron - electron-pdf-window - View PDF files in browser windows. (Tools / For Electron)
- awesome-electron - electron-pdf-window - View PDF files in browser windows.  (Library / Uncategorized)
- awesome-electron-zh - electron-pdf-window - View PDF files in browser windows. (Tools / For Electron)
README
# electron-pdf-window
view PDF files in electron browser windows. this module adds support for viewing
PDF files in electron [`BrowserWindow`s](http://electron.atom.io/docs/api/browser-window/).
it works even if you navigate to a PDF file from a site, or opening a PDF file in
a new window. a `PDFWindow` instance is just a subclass of `BrowserWindow` so it
can be used just like it.
![]()
``` javascript
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.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf')
})
```## install
```
$ npm i electron-pdf-window
```## usage
#### `win = new PDFWindow([opts])`
`win` is an electron [`BrowserWindow`](http://electron.atom.io/docs/api/browser-window/)
that has support for viewing PDF files.#### `PDFWindow.addSupport(win)`
adds PDF viewing support for `win`, which is a `BrowserWindow` instance.## using from the renderer process
Using the `PDFWindow` class directly from the renderer process is not
recommended, because electron doesn't support proper extending of their built-in
classes. In order to add PDF support from the renderer, use the `addSupport`
method.``` js
const { BrowserWindow } = require('electron').remote
const PDFWindow = require('electron-pdf-window')const win = new BrowserWindow({ width: 800, height: 600 })
PDFWindow.addSupport(win)
win.loadURL('file:///a/b/c.pdf')
```## test
```
$ npm test
```