diff --git a/README.md b/README.md index baeba25..7bd1f7a 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,16 @@ Wrapper for ghostscript in node.js. } }); + // OR + .writetostream(writeableStream, function(err) { + if (!err) { + console.log(success); + //dostuff with write stream + } else { + console.log(err); + } + }); + ## API * `batch` @@ -38,6 +48,16 @@ Wrapper for ghostscript in node.js. * `output` * `r` * `quiet` +* `firstpage` +* `lastpage` +* `aligntopixels` +* `textalphabits` +* `graphicsalphabits` +* `epscrop` +* `usecropbox` +* `gridfitt` +* `gridfitt` +* `writetostream` ## Test diff --git a/index.js b/index.js index af43e9d..a554a80 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ -var exec = require('child_process').exec; +var exec = require('child_process').exec, + spawn = require('child_process').spawn; var create = function() { return new gs(); @@ -31,6 +32,30 @@ gs.prototype.exec = function(callback) { }); }; +gs.prototype.writetostream = function(writestream, callback){ + var self = this, + errorString = ''; + + this.options.push('-sOutputFile=%stdout'); + this.options.push(this._input); + + var gsProcess = spawn('gs', this.options); + + gsProcess.stderr.on('data', function (data) { + errorString += data; + }); + + gsProcess.on('close', function (code) { + if (code !== 0) { + callback({msg: errorString, exitcode: code}); + } else { + callback(null); + } + }); + + gsProcess.stdout.pipe(writestream); +}; + gs.prototype.input = function(file) { this._input = file; return this; @@ -40,11 +65,66 @@ gs.prototype.jpegq = function(value) { value = value || 75; this.options.push('-dJPEGQ=' + value); return this; +} + +gs.prototype.firstpage = function(value) { + this.options.push('-dFirstPage#' + value); + return this; +}; + +gs.prototype.lastpage = function(value) { + this.options.push('-dLastPage#' + value); + return this; +}; + +gs.prototype.aligntopixels = function(value) { + this.options.push('-dAlignToPixels#' + value); + return this; +}; + +gs.prototype.textalphabits = function(value) { + this.options.push('-dTextAlphaBits#' + value); + return this; +}; + +gs.prototype.gridfitt = function(value) { + this.options.push('-dGridFitTT#' + value); + return this; +}; + +gs.prototype.graphicsalphabits = function(value) { + this.options.push('-dGraphicsAlphaBits#' + value); + return this; }; +gs.prototype.epscrop = function() { + this.options.push('-dEPSCrop'); + return this; +} + +gs.prototype.epsfitpage = function() { + this.options.push('-dEPSFitPage'); + return this; +} + +gs.prototype.translate = function(x, y) { + this.options.push(x+' '+y+' translate'); + return this; +} + +gs.prototype.usecropbox = function() { + this.options.push('-dUseCropBox'); + return this; +} + gs.prototype.nopause = function() { this.options.push('-dNOPAUSE'); return this; +} + +gs.prototype.safer = function() { + this.options.push('-dSAFER'); + return this; }; gs.prototype.output = function(file) { @@ -61,6 +141,11 @@ gs.prototype.quiet = function() { return this; }; +gs.prototype.g = function(xres, yres) { + this.options.push('-g' + xres + (yres ? 'x' + yres : '')); + return this; +}; + gs.prototype.resolution = function(xres, yres) { this.options.push('-r' + xres + (yres ? 'x' + yres : '')); return this; diff --git a/package.json b/package.json index 21cfbaf..05f1b8b 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/musubu/node-ghostscript.git" + "url": "https://github.com/axomic/node-ghostscript.git" }, "keywords": [ "ghostscript", @@ -38,4 +38,4 @@ "engine": { "node": ">=0.8.16" } -} \ No newline at end of file +}