From 84b405afa800e91b2ef9a3697e4b628946c93cc4 Mon Sep 17 00:00:00 2001 From: Dustin Coffey Date: Sat, 27 Feb 2016 19:31:12 -0800 Subject: [PATCH] Add non-zero based numbering for outputImagePath. --- index.js | 6 +++++- tests/test-main.js | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index ee5dd64..1d9c9ca 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,7 @@ function PDFImage(pdfFilePath, options) { this.useGM = options.graphicsMagick || false; this.outputDirectory = options.outputDirectory || path.dirname(pdfFilePath); + this.nonZeroBased = options.nonZeroBased || false; } PDFImage.prototype = { @@ -60,9 +61,12 @@ PDFImage.prototype = { }); }, getOutputImagePathForPage: function (pageNumber) { + var fileName = this.pdfFileBaseName + + "-" + ((this.nonZeroBased) ? (~~pageNumber+1) : pageNumber) + + "." + this.convertExtension; return path.join( this.outputDirectory, - this.pdfFileBaseName + "-" + pageNumber + "." + this.convertExtension + fileName ); }, setConvertOptions: function (convertOptions) { diff --git a/tests/test-main.js b/tests/test-main.js index b5af150..17ff3dd 100644 --- a/tests/test-main.js +++ b/tests/test-main.js @@ -26,6 +26,14 @@ describe("PDFImage", function () { .equal("/tmp/test-1000.png"); }); + it("should return non-zero based page path", function () { + pdfImage = new PDFImage(pdfPath, { nonZeroBased: true }); + expect(pdfImage.getOutputImagePathForPage(0)) + .equal("/tmp/test-1.png"); + expect(pdfImage.getOutputImagePathForPage(2)) + .equal("/tmp/test-3.png"); + }); + it("should return correct convert command", function () { expect(pdfImage.constructConvertCommandForPage(1)) .equal("convert '/tmp/test.pdf[1]' '/tmp/test-1.png'");