Skip to content

Commit d3f78c6

Browse files
committed
Merge pull request blend#1 from picnichealth/master
Merging "get num pages" from another fork
2 parents e56a009 + 6859ba5 commit d3f78c6

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "scissors.js",
66
"dependencies": {
77
"async": "^0.9.0",
8+
"bluebird": "^2.9.14",
89
"bufferjs": "~2.0.0",
910
"bufferstream": "^0.6.2",
1011
"temp": "^0.8.1"

scissors.js

+28
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var Stream = require('stream').Stream;
66
var BufferStream = require('bufferstream');
77
var temp = require('temp').track();
88
var async = require('async');
9+
var Bluebird = require('bluebird');
910

1011
// Calls functions once a promise has been delivered.
1112
// Queue functions by using promise(yourCallback); Deliver the promise using promise.deliver().
@@ -183,6 +184,33 @@ Command.prototype.crop = function (l, b, r, t) {
183184
return cmd._push([path.join(__dirname, 'bin/crop.js'), l, b, r, t]);
184185
};
185186

187+
188+
Command.prototype.dumpData = function () {
189+
var cmd = this._copy();
190+
cmd._push([
191+
'pdftk', cmd._input(),
192+
'dump_data'
193+
]);
194+
return cmd._exec();
195+
};
196+
197+
Command.prototype.getNumPages = function() {
198+
var self = this;
199+
return new Bluebird(function(resolve, reject) {
200+
var output = '';
201+
self.dumpData()
202+
.on('data', function(buffer) {
203+
var part = buffer.toString();
204+
output += part;
205+
})
206+
.on('end', function() {
207+
var re = new RegExp("NumberOfPages\: ([0-9]+)", "g");
208+
var matches = re.exec(output);
209+
resolve(matches[1]);
210+
})
211+
.on('error', reject);
212+
});
213+
};
186214
Command.prototype.pdfStream = function () {
187215
var cmd = this.repair();
188216
return cmd._exec();

0 commit comments

Comments
 (0)