Example #1
0
  keys.forEach(function(key) {
    var val = options[key];
    if (key === 'ignore' || key === 'debug' || key === 'debugStdOut') { // skip adding the ignore/debug keys
      return false;
    }

    if (key !== 'toc' && key !== 'cover' && key !== 'page') {
      key = key.length === 1 ? '-' + key : '--' + slang.dasherize(key);
    }

    if (Array.isArray(val)) { // add repeatable args
      val.forEach(function(valueStr) {
        args.push(key);
        if (Array.isArray(valueStr)) { // if repeatable args has key/value pair
          valueStr.forEach(function(keyOrValueStr) {
            args.push(quote(keyOrValueStr));
          });
        } else {
          args.push(quote(valueStr));
        }
      });
    } else { // add normal args
      if (val !== false) {
        args.push(key);
      }

      if (typeof val !== 'boolean') {
        args.push(quote(val));
      }
    }
  });
 keys.forEach(function(key) {
   var val = options[key];
   if (key !== 'toc' && key !== 'cover' && key !== 'page')
     key = key.length === 1 ? '-' + key : '--' + slang.dasherize(key);
   
   if (val !== false)
     args.push(key);
     
   if (typeof val !== 'boolean')
     args.push(quote(val));
 });
Example #3
0
		Object.keys(options).forEach(function(key) {
			if (typeof options[key] === 'object') {
				Object.keys(options[key]).forEach(function(k) {
					args.push('--' + slang.dasherize((key)));
					args.push(k);
					args.push(options[key][k]);
				})
			} else {
				args.push('--' + slang.dasherize(key));
				if (typeof options[key] === 'string' || typeof options[key] === 'number') {
					args.push(options[key]);
				}
			}
		});
Example #4
0
function wkhtmltopdf(input, options, callback) {
  if (!options)
    options = {};
  else if (options === typeof 'function') {
    callback = options;
    options = {};
  }
  
  var output = options.output;
  delete options.output;
  
  var args = [wkhtmltopdf.command, '--quiet'];
  for (var key in options) {
    var val = options[key];
    key = key.length === 1 ? '-' + key : '--' + slang.dasherize(key);
    
    if (val !== false)
      args.push(key);
      
    if (typeof val !== 'boolean') {
      // escape and quote the value if it is a string
      if (typeof val === 'string')
        val = '"' + val.replace(/(["\\$`])/g, '\\$1') + '"';
        
      args.push(val);
    }
  }
  
  var isUrl = /^(https?|file):\/\//.test(input);
  args.push(isUrl ? input : '-'); // stdin if HTML given directly
  args.push(output || '-');       // stdout if no output file
  
  // this nasty business prevents piping problems on linux
  var child = spawn('/bin/sh', ['-c', args.join(' ') + ' | cat']);

  if (callback)
    child.on('exit', callback);

  if (!isUrl)
    child.stdin.end(input);
  
  // return stdout stream so we can pipe
  return child.stdout;
}
Example #5
0
function wkhtmltopdf(input, options, callback) {
  if (!options) {
    options = { quiet: true, logging: false, };
  } else if (typeof options == 'function') {
    callback = options;
    options = { quiet: true, logging: false, };
  }
  var logging = options.logging ? options.logging===true ? true : false : false;
  delete options.logging;
  
  var output = options.output;
  delete options.output;
  
  var args = [];
  args.push(wkhtmltopdf.command );
  
  if ( options.quiet )
    args.push('--quiet');
  delete options.quiet;


  for (var key in options) {
    var val = options[key];
    key = key.length === 1 ? '-' + key : '--' + slang.dasherize(key);
    
    if (val !== false)
      args.push(key);
      
    if (typeof val !== 'boolean') {
      // escape and quote the value if it is a string
      if (typeof val === 'string')
        val = '"' + val.replace(/(["\\$`])/g, '\\$1') + '"';
        
      args.push(val);
    }
  }

  var isUrl = /^(https?|file):\/\//.test(input);
  if (process.platform === 'win32')
    input = '"' + input + '"';

  args.push(isUrl ? input : '-'); // stdin if HTML given directly
  args.push(output || '-');       // stdout if no output file

  if (process.platform === 'win32') {
    args.unshift('"');    
    args.unshift('/C');
    args.push('"');
    
    if (logging) {
      console.log('WKHTMLTOPDF args:\n');
      console.dir(args);
      console.log('\n');
    }
    
    var child = spawn('cmd', args, { windowsVerbatimArguments: true });
    if (logging) logError(child);
  } else {
    // this nasty business prevents piping problems on linux
    var child = spawn('/bin/sh', ['-c', args.join(' ') + ' | cat']);
    if (logging) logError(child);
  }

  if (callback)
    child.on('exit', callback);

  if (!isUrl)
    child.stdin.end(input);
  
  // return stdout stream so we can pipe
  return child.stdout;
}
Example #6
0
				Object.keys(options[key]).forEach(function(k) {
					args.push('--' + slang.dasherize((key)));
					args.push(k);
					args.push(options[key][k]);
				})