0.1.1 • Published 8 years ago
node-gs v0.1.1
node-gs 
NodeJS wrapper for gs (GhostScript).
Built upon node-gs by Nick Campbell and many others.
Installation
npm install --save node-gsUsage
Sample usage:
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):
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 {
// ( ͡° ͜ʖ ͡°)
}
});
}API
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 totxtwriteexecutablePath- path to the Ghostscript executable files (example:ghostscript/bin/./gs)include- set path togs_init.psfile (portable Ghostscript) array of include pathsinput- file or data for stdin (when invoked withgs( '-' ))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
Events
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() );
});