electron-viewerjs

1.0.2 • Public • Published

Electron ViewerJS

The PDF/ODT/ODP embedded viewer based on ViewerJS for Electron.

screen-shot-1

Installation

$ npm i --save electron-viewerjs

Usage

Enable webviewTag in main.js:

mainWindow = new BrowserWindow({
    ...
    webPreferences: {
      preload: path.join(__dirname, 'preload.js'),
      nodeIntegration: true,
      webviewTag: true //Enable webviewTag
    }
    ...
  })

Declare container in index.html

<div id="sample-viewer-1" style="width: 100%; height: 100%;"></div>
<div id="sample-viewer-2" data-src="./sample-pdf2-doc.pdf" style="width: 100%; height: 100%;"></div>

Declare viewer in renderer.js

const viewer = require('electron-viewerjs');

There are 3 ways of initialize

  1. Load file at constructor
let ctx = document.getElementById('sample-viewer-1');
viewer.new(ctx, {path: './sample-pdf1-doc.pdf'});
  1. Load file by attribute data-src="..."
let ctx = document.getElementById('sample-viewer-2');
viewer.new(ctx); //No need to put path here.
  1. Load file after initialized
let ctx = document.getElementById('sample-viewer-1');
let preview = viewer.new(ctx);
preview.loadSync('./sample-odt-doc.odt'); //Load ODT document file after initialized.

Package Sidebar

Install

npm i electron-viewerjs

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

2.06 MB

Total Files

24

Last publish

Collaborators

  • vee.jirapong