forked from TJkrusinski/NodePDF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (34 loc) · 941 Bytes
/
index.js
File metadata and controls
43 lines (34 loc) · 941 Bytes
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
var child = require('./child.js');
module.exports = function(url, filename, opts){
var ps,
readStream,
me = this;
this.evts = {};
this.options = {
width: opts && opts.width ? parseInt(opts.width, 10)*2 : 2880,
height: opts && opts.height ? parseInt(opts.height, 10)*2 : 1440,
args : opts && opts.args ? opts.args : ''
};
this.url = url;
this.filename = filename;
this.on = function(evt, callback){
this.evts[evt] = callback;
};
ps = child.child(this.url, this.filename, this.options);
readStream = function(stream){
if(stream.toString('utf-8').length === 2){
me.evts['done'].call(this, process.env.PWD+'/'+filename);
ps.kill();
} else {
me.evts['error'].call(this, 'There was a problem');
};
};
ps.stdout.on('data', function(std){
//console.log('stdout from phantom: '+std);
readStream(std);
});
ps.stderr.on('data', function(std){
me.evts['error'].call(me, std);
});
return this;
};