From d8df2519bb456eb232c50296e9d19bf64af3fd32 Mon Sep 17 00:00:00 2001 From: John Louis Swaine Date: Wed, 14 May 2014 10:56:16 +0000 Subject: [PATCH 1/3] Adds support for more commands and piping gs output to a writable stream --- README.md | 20 +++++++++++++++ index.js | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 96 insertions(+), 1 deletion(-) 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..04eb2be 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,56 @@ 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.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 +131,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; From a7a8c59e1f6f842e60c334dcd9fdf7444bdc73b2 Mon Sep 17 00:00:00 2001 From: johnlouis-swaine-axomic Date: Fri, 13 Jan 2017 11:46:12 +0000 Subject: [PATCH 2/3] Added a few more commands needed for EPS processing --- index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/index.js b/index.js index 04eb2be..a554a80 100644 --- a/index.js +++ b/index.js @@ -102,6 +102,16 @@ gs.prototype.epscrop = function() { 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; From cab6322278c5fab0ed28f683f8382dadbc73e475 Mon Sep 17 00:00:00 2001 From: johnlouis-swaine-axomic Date: Mon, 16 Jan 2017 11:05:29 +0000 Subject: [PATCH 3/3] Updated package.json --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 +}