diff --git a/README.md b/README.md index 2ac37b4..9798e36 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,10 @@ pdfImage.convertPage(0).then(function (imagePath) { fs.existsSync("/tmp/slide-0.png") // => true }); ``` +> Note: If you do NOT want page numbers in your image file names, use option "omitPageNumOnFileName" +``` +pdfImage.convertPage(0, {omitPageNumOnFileName:true}).then() +``` ## Express diff --git a/index.js b/index.js index ee5dd64..b7fe46d 100644 --- a/index.js +++ b/index.js @@ -59,10 +59,11 @@ PDFImage.prototype = { return info["Pages"]; }); }, - getOutputImagePathForPage: function (pageNumber) { + /** @options{omitPageNumOnFileName:Boolean} */ + getOutputImagePathForPage: function (pageNumber, options) { return path.join( this.outputDirectory, - this.pdfFileBaseName + "-" + pageNumber + "." + this.convertExtension + this.pdfFileBaseName + (!options||!options.omitPageNumOnFileName?"-"+pageNumber:"") + "." + this.convertExtension ); }, setConvertOptions: function (convertOptions) { @@ -71,9 +72,9 @@ PDFImage.prototype = { setConvertExtension: function (convertExtension) { this.convertExtension = convertExtension || "png"; }, - constructConvertCommandForPage: function (pageNumber) { + constructConvertCommandForPage: function (pageNumber, options) { var pdfFilePath = this.pdfFilePath; - var outputImagePath = this.getOutputImagePathForPage(pageNumber); + var outputImagePath = this.getOutputImagePathForPage(pageNumber, options); var convertOptionsString = this.constructConvertOptions(); return util.format( "%s %s'%s[%d]' '%s'", @@ -91,10 +92,10 @@ PDFImage.prototype = { } }, this).join(" "); }, - convertPage: function (pageNumber) { + convertPage: function (pageNumber, options) { var pdfFilePath = this.pdfFilePath; - var outputImagePath = this.getOutputImagePathForPage(pageNumber); - var convertCommand = this.constructConvertCommandForPage(pageNumber); + var outputImagePath = this.getOutputImagePathForPage(pageNumber, options); + var convertCommand = this.constructConvertCommandForPage(pageNumber, options); var promise = new Promise(function (resolve, reject) { function convertPageToImage() { diff --git a/package.json b/package.json index c090775..84e4de4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pdf-image", - "version": "1.0.2", + "version": "1.0.3", "main": "index.js", "repository": { "type": "git", diff --git a/tests/test-main.js b/tests/test-main.js index b5af150..0a7684e 100644 --- a/tests/test-main.js +++ b/tests/test-main.js @@ -24,6 +24,8 @@ describe("PDFImage", function () { .equal("/tmp/test-2.png"); expect(pdfImage.getOutputImagePathForPage(1000)) .equal("/tmp/test-1000.png"); + expect(pdfImage.getOutputImagePathForPage(1000,{omitPageNumOnFileName:true})) + .equal("/tmp/test.png"); }); it("should return correct convert command", function () {