From 432a07866759e73bdfc6942e5f32ee49b874adf2 Mon Sep 17 00:00:00 2001 From: Roy Hill-Percival Date: Mon, 8 Oct 2018 10:09:08 -0400 Subject: [PATCH] Ensure the image paths are sorted naturally (numerically) so that 10 and 11 come after 1-9 --- index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 4fa6231..78e107f 100644 --- a/index.js +++ b/index.js @@ -137,7 +137,14 @@ PDFImage.prototype = { pdfImage.convertPage(i).then(function(imagePath){ imagePaths.push(imagePath); if (imagePaths.length === parseInt(totalPages)){ - imagePaths.sort(); //because of asyc pages we have to reSort pages + // Ensure that filenames are sorted naturally (numerically) + imagePaths.sort(function (a,b) { + a = a.split('-') + a = a[a.length - 1].split('.')[0] + b = b.split('-') + b = b[b.length - 1].split('.')[0] + return a - b; + }); //because of asyc pages we have to reSort pages resolve(imagePaths); } }).catch(function(error){