你应该能够页码的数组传递给函数。 我接过一看scissors source code,他们似乎采取实际的参数自理:
/**
* Creates a copy of the pages with the given numbers
* @param {(...Number|Array)} Page number, either as an array or as arguments
* @return {Command} A chainable Command instance
*/
Command.prototype.pages = function() {
var args = (Array.isArray(arguments[0])) ?
arguments[0] : Array.prototype.slice.call(arguments);
var cmd = this._copy();
return cmd._push([
'pdftk', cmd._input(),
'cat'].concat(args.map(Number), [
'output', '-'
]));
};
您可以通过将被组合成阵列Array.prototype.slice
多个参数或只是通过将用于数组直。
var scissors = require('scissors');
var pages = [];
/* collect desired pages */
pages.push(23);
pages.push(42);
pages.push(1337);
var pdf = scissors('in.pdf').pages(pages);
还有的[ES6传播语法(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator) –