Created
June 13, 2014 21:38
-
-
Save remy/259cd538282eea21d740 to your computer and use it in GitHub Desktop.
Converts HTML slides (usually via reveal) to a PDF - useful for video editing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*global console:true, phantom:true, slidedeck:true*/ | |
var webpage = require('webpage'), | |
page = webpage.create(), | |
system = require('system'), | |
url = system.args[1] || 'index.html', | |
fs = require('fs'), | |
imageSources = [], | |
imageTags, | |
width = system.args[2] || 1920, | |
height = system.args[3] || 1080; | |
function onLoadFinished(status) { | |
"use strict"; | |
var slideCount; | |
if (status !== 'success') { | |
console.log('Target file not found.'); | |
phantom.exit(); | |
} | |
page.paperSize = { width: width, height: height, border: '0px' }; | |
page.clipRect = { top: 0, left: 0, width: width, height: height }; | |
page.viewportSize = { width: width, height: height }; | |
slideCount = page.evaluate(function(width, height) { | |
var s = document.createElement('style'); | |
s.innerHTML = 'html, body { background: black; width: ' + width + 'px; height: ' + height + 'px; overflow: hidden; } * { -webkit-transition: all 0ms !important; } slide { width: ' + width + 'px !important; }'; | |
document.head.appendChild(s); | |
return document.querySelectorAll('slide').length; | |
}, 'width', 'height'); | |
fs.makeDirectory('temp-slides'); | |
console.log('Slide has ' + slideCount + ' slides'); | |
var i = 0; | |
setTimeout(function () { | |
var lasturl = null; | |
var timer = setInterval(function () { | |
i++; | |
console.log(page.url); | |
if (page.url === lasturl) {//i > slideCount) { | |
clearInterval(timer); | |
phantom.exit(); | |
return; | |
} | |
console.log('Doing ' + i); | |
var src = 'temp-slides/output-' + i + '.png'; | |
imageSources.push(src); | |
console.log('Rendering slide #' + i); | |
page.render(src); | |
console.log('Done slide #' + i); | |
lasturl = page.url; | |
page.evaluate(function() { | |
// This is the bespoke method of progressing through the slides | |
slidedeck.nextSlide(); | |
}); | |
}, 250); | |
}, 1000); | |
} | |
page.open(url, onLoadFinished); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment