NodeJS wrapper for gs (ghostscript)
npm install node-gsnode-gs 
=====
NodeJS wrapper for gs (GhostScript).
Built upon node-gs by Nick Campbell and many others.
Installation
=====
``sh`
npm install --save node-gs
Usage
=====
Sample usage:
`javascript
var gs = require( 'node-gs' );
gs()
.batch()
.nopause()
.option( '-r' + 50 * 2 )
.option( '-dDownScaleFactor=2' )
.device( 'png16m' )
.input( '/tmp/' + fileName )
.output( '/tmp/' + fileName + '-%d.png' )
// optional:
.executablePath( 'ghostscript/bin/./gs' )
.exec( function ( error, stdout, stderr ) {
if ( error ) {
// ¯\_(ツ)_/¯
} else {
// ( ͡° ͜ʖ ͡°)
}
});
`
Usage with piping input and output (for use within the NodeJS app):
`javascript
var gs = require( 'node-gs' ),
fs = require( 'fs' ),
input = fs.readFileSync( '/tmp/' + fileName );
if ( input ) {
gs()
.option( '-r' + 50 * 2 )
.option( '-dDownScaleFactor=2' )
.device( 'png16m' )
.exec( input, function ( error, stdout, stderr ) {
if ( error ) {
// ¯\_(ツ)_/¯
} else {
// ( ͡° ͜ʖ ͡°)
}
});
}
`
* batch - set batch optioncommand
* - tell gs to interpret PostScript codecurrentDirectory
* / p - tell gs to use current directory for libraries firstdiskfonts
* - set diskfonts optiondefine
* - set definition with valuedevice
* - device - defaults to txtwriteexecutablePath
* - path to the Ghostscript executable files (example: ghostscript/bin/./gs)include
* - set path to gs_init.ps file (portable Ghostscript)input
array of include paths
* - file or data for stdin (when invoked with gs( '-' ))nobind
* - set nobind optionnocache
* - set nocache optionnodisplay
* - set nodisplay optionnopause
* - set nopause optionoption
* - add any option that is not provided through the methodsoutput
* - file - defaults to - which represents stdoutpage
* - number - tell gs to process single pagepagecount
* - return number of pagespages
* - numbers - tell gs to process page rangepapersize
* - set the paper sizequiet
* / q - tell gs to be quietreset
* - reset gs to initial stateresolution
* / res / r - set device resolutionsafer
* - set gs to run in safe modeexec
* - callback
`javascript
var gs = require( 'node-gs' );
gs( inputFile )
.output( outputFile )
.on( 'pages', function ( from, to ) {
console.debug( '[sg] Processing pages ' + from + '-' * to );
})
.on( 'page', function ( page ) {
console.debug( '[sg] Processing page:', page );
})
.on( 'data', function ( data ) {
console.log( '[sg] Data:', data.toString() );
})
.exec( function ( err, data ) {
console.log( '[sg] Data:', data.toString() );
});
``
MIT - http://miro.mit-license.org/