- Eric Schrijver
- S V
- Ludivine Loiseau
var casper = require('casper').create({
viewportSize : {width: 1190, height: 873},
verbose: true,
logLevel: "debug"
});
var chapters = JSON.parse(fs.read('toc.json'));
var makeUris = function(names) {
var uris = [];
for (var i=0; i
uris.push('http://relearn.be/r/' + names[i]);
}
return uris;
};
var deUri = function(uri) {
return uri.replace('http://relearn.be/r/', '');
};
casper.start();
casper.page.paperSize = { format: 'A4', orientation: 'portrait',
margin: {
left : "50mm",
top : "15mm",
right : "15mm",
bottom : "21mm"
}
};
var chapterCounter = 1;
casper.thenOpen ('http://relearn.be/r/cover.html', function () {
this.capture('render/00-Cover.pdf');
});
casper.eachThen (chapters, function (chapterdata) {
var chapter = chapterdata.data;
this.then(function() {
counter = 1;
});
this.thenOpen ('http://relearn.be/', function() {
this.evaluate (function (chapter, chapterCounter) {
$("#content").html('
' + chapterCounter + ' ' + chapter['title'] + '
');}, chapter, chapterCounter);
this.capture ('render/' + chapterCounter + '-' + counter + '-' + chapter['title'] + '.pdf');
});
this.eachThen(makeUris(chapter['pads']), function(response) {
this.thenOpen(response.data, function(response) {
casper.waitFor(function check() {
return this.evaluate(function () {
return $("img:not([src$=svg])").length === 0;
});
}, function then() {
this.capture('render/' + chapterCounter + '-' + counter + '-' + deUri(response.url) + '.pdf');
}, function timeout() {
this.capture('render/' + chapterCounter + '-' + counter + '-' + deUri(response.url) + '.pdf')
}, 5000);
});
counter += 1;
});
this.then (function () {
chapterCounter += 1;
});
});
casper.run();