Skip to content

Instantly share code, notes, and snippets.

@Anna-Myzukina
Last active August 27, 2018 06:34
Show Gist options
  • Save Anna-Myzukina/6d5cb76d3f7f3428790b77e5f678c0b8 to your computer and use it in GitHub Desktop.
Save Anna-Myzukina/6d5cb76d3f7f3428790b77e5f678c0b8 to your computer and use it in GitHub Desktop.
elementary-electron
var electron = require('electron')
electron.app.on('ready', function () {
var mainWindow = new electron.BrowserWindow({width: 600, height: 800})
mainWindow.loadURL('file://' + __dirname + '/index.html')
})
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>Hello World</h1>
<div id='visualization'></div>
<script type="text/javascript" src="index.js"></script>
</body>
</html>
var remote = require('electron').remote
var fs = require('fs')
var image = require('lightning-image-poly')
var picture = require('cat-picture')
var src = picture.src
picture.remove()
var viz = new image('#visualization', null, [src], {hullAlgorithm: 'convex'})
function save() {
remote.getCurrentWindow().webContents.printToPDF({
portrait: true,
}, function(err, data) {
fs.writeFile('annotation.pdf', data, function(err) {
if (err) alert('error generating pdf! ' + err.message)
else alert('pdf saved!')
})
})
}
window.addEventListener('keydown', function(e) {
if (e.keyCode === 80) save()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment