-
Notifications
You must be signed in to change notification settings - Fork 0
/
bigout.js
63 lines (48 loc) · 1.28 KB
/
bigout.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// args validation and variable assignment
var argslen = process.argv.length;
if (argslen < 5) {
console.log('missing args');
console.log('Usage: $ node bigout.js http://example-big-presentation.com startNum endNum');
process.exit(1);
}
var url = process.argv[2];
var start = process.argv[3];
var end = process.argv[4];
// shelljs to call local phantomjs
var shell = require('shelljs');
var phjs = 'node_modules/phantomjs/bin/phantomjs';
shell.exec(phjs+' index.js '+url+' '+start+' '+end);
// PDF Kit
var PDFDocument = require('pdfkit');
var fs = require('fs');
var outDir = fs.readdirSync('outputs/');
var outputs = [];
for (var i=0; i < outDir.length; i++){
if (outDir[i].split('.')[1] === 'png'){
outputs.push(outDir[i]);
}
}
var doc_options = {
size: 'A4',
layout: 'landscape',
info: {
Title: 'big.js presentation',
Author: 'bigOut'
}
}
var doc = new PDFDocument(doc_options);
var outDoc = fs.createWriteStream('bigOut.pdf');
doc.pipe(outDoc);
for (var i=0; i < outputs.length; i++){
if (i > 0){
doc.addPage();
}
doc.image('outputs/'+outputs[i], 0, 0, {width: 841, height: 595});
}
for (var i=0; i < outDir.length; i++){
if (outDir[i].split('.')[1] === 'png'){
fs.unlink('outputs/'+outDir[i]);
}
}
// finalize the PDF and end the stream
doc.end();