-
Notifications
You must be signed in to change notification settings - Fork 1
/
node-ghostscript.js
62 lines (62 loc) · 1.67 KB
/
node-ghostscript.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
var exec = require('child_process').exec;
var create = function () {
return new gs();
};
var gs = function () {
this.options = [];
this._input = null;
};
gs.prototype.batch = function () {
this.options.push('-dBATCH');
return this;
};
gs.prototype.device = function (device) {
device = device || 'jpeg';
this.options.push('-sDEVICE=' + device);
return this;
};
gs.prototype.exec = function (callback) {
var self = this;
if (!this._input) return callback("Please specify input");
var args = this.options.concat([this._input]).join(' ');
exec('gs ' + args, function (err, stdout, stderr) {
callback(err, stdout, stderr);
});
};
gs.prototype.input = function (file) {
this._input = file;
return this;
};
gs.prototype.nopause = function () {
this.options.push('-dNOPAUSE');
return this;
};
gs.prototype.output = function (file) {
file = file || '-';
this.options.push('-sOutputFile=' + file);
if (file === '-') return this.quiet();
return this;
};
gs.prototype.q = gs.prototype.quiet;
gs.prototype.quiet = function () {
this.options.push('-dQUIET');
return this;
};
gs.prototype.firstPage = function (firstPage) {
this.options.push('-dFirstPage=' + firstPage);
return this;
};
gs.prototype.lastPage = function (lastPage) {
this.options.push('-dLastPage=' + lastPage);
return this;
};
gs.prototype.option = function (option) {
this.options.push(option);
return this;
};
gs.prototype.resolution = function (xres, yres) {
this.options.push('-r' + xres + (yres ? 'x' + yres : ''));
return this;
};
gs.prototype.r = gs.prototype.res = gs.prototype.resolution;
module.exports = create;