Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Add non-zero based numbering for page paths. #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions tests/test-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'");
Expand Down