Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Offline Rendering of @kig's Message presentation app using SlimerJS
/*
PDF Generator for @ilmarihei's Awesome "Messsage" Presentation App!
Usage:
./slimerjs messages.js
You may also need to
- get http://slimerjs.org/
- edit the config variables
- run `convert slides/*.jpg presentation.pdf`
Cheers,
@blurspline
*/
var TARGET = 'https://viewmessage.fhtr.net/?page=view&id=51dad76876241f0200000002'
var SCREEN_SHOT_DELAY = 1000;
var WIDTH = 1024;
var HEIGHT = 768;
console.log("Hello Messages PDF Generator!");
var webpage = require("webpage");
var page = webpage.create();
var downloaded = {};
page.onConsoleMessage = function (msg) {
console.log(msg);
var match = msg.match(/Slide[ ](\d+)\/(\d+)/);
if (match && match.length == 3) {
if (match[1] in downloaded) return;
downloaded[match[1]] = true;
console.log(match);
setTimeout(function() {
page.render('slides/' + match[1] + '.jpg', { format: "jpg", quality: 100 });
page.sendEvent('keyup', page.event.key.Right);
if (match[1] == match[2]) {
console.log('last slide.')
page.end()
phantomjs.exit();
return;
}
}, SCREEN_SHOT_DELAY);
}
};
page.onResourceReceived = function (response) {
if (response.stage=='end') console.log('downloaded: ' + response.url)
};
page.viewportSize = { width: WIDTH, height: HEIGHT };
page.open(TARGET);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment