Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple pdf files to be converted #40

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed using gm as node_module to identify pages
  • Loading branch information
Vladislav Stoitsov authored Jul 11, 2017
commit f65c79558e65b819cb2c2b4fc95a6007051a597d
53 changes: 28 additions & 25 deletions lib/pdf2img.js
Original file line number Diff line number Diff line change
@@ -66,32 +66,35 @@ Pdf2Img.prototype.convert = function(input, callbackreturn) {

async.waterfall([
// Get pages count
function(callback) {
var cmd = 'gm identify -format "%p " "' + input + '"';
var execSync = require('child_process').execSync;
var pageCount = execSync(cmd).toString().match(/[0-9]+/g);
function (callback) {
gm(input).identify("%p ", function (err, value) {
var pageCount = String(value).split(' ');

if (!pageCount.length) {
callback({
result: 'error',
message: 'Invalid page number.'
}, null);
} else {
// Convert selected page
if (options.page !== null) {
if (options.page < pageCount.length) {
callback(null, [options.page]);
} else {
callback({
result: 'error',
message: 'Invalid page number.'
}, null);
}
} else {
callback(null, pageCount);
}
}

})

},

if (!pageCount.length) {
return callback({
result: 'error',
message: 'Invalid page number.'
}, null);
}

// Convert selected page
if (options.page !== null) {
if (options.page < pageCount.length) {
return callback(null, [options.page]);
} else {
return callback({
result: 'error',
message: 'Invalid page number.'
}, null);
}
}

return callback(null, pageCount);
},

// Convert pdf file
function(pages, callback) {