Skip to content

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

Notifications You must be signed in to change notification settings

xenirio/electron-viewerjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages