Comparing version 1.0.1 to 1.0.2
18
index.js
@@ -16,3 +16,4 @@ // node-pdf | ||
this.setConvertOptions(options.convertOptions || {}); | ||
this.setConvertOptions(options.convertOptions); | ||
this.setConvertExtension(options.convertExtension); | ||
@@ -65,3 +66,3 @@ // TODO: make out dir customizable | ||
this.outputDirectory, | ||
this.pdfFileBaseName + "-" + pageNumber + ".png" | ||
this.pdfFileBaseName + "-" + pageNumber + "." + this.convertExtension | ||
); | ||
@@ -72,9 +73,12 @@ }, | ||
}, | ||
setConvertExtension: function (convertExtension) { | ||
this.convertExtension = convertExtension || "png"; | ||
}, | ||
constructConvertCommandForPage: function (pageNumber) { | ||
var pdfFilePath = this.pdfFilePath; | ||
var outputImagePath = this.getOutputImagePathForPage(pageNumber); | ||
var convertOptionString = this.constructConvertOptions(); | ||
var outputImagePath = "\""+this.getOutputImagePathForPage(pageNumber)+"\""; | ||
var convertOptionsString = this.constructConvertOptions(); | ||
return util.format( | ||
"convert %s'%s[%d]' %s", | ||
convertOptionString ? convertOptionString + " " : "", | ||
"convert %s'%s[%d]' '%s'", | ||
convertOptionsString ? convertOptionsString + " " : "", | ||
pdfFilePath, pageNumber, outputImagePath | ||
@@ -153,2 +157,2 @@ ); | ||
exports.PDFImage = PDFImage; | ||
exports.PDFImage = PDFImage; |
{ | ||
"name": "pdf-image", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -16,2 +16,6 @@ # pdf-image | ||
### OSX (Yosemite) | ||
brew install imagemagick ghostscript poppler | ||
## Usage | ||
@@ -24,3 +28,3 @@ | ||
pdfImage.convertPage(0).then(function (imagePath) { | ||
// 0-th page (fisrt page) of the slide.pdf is available as slide-0.png | ||
// 0-th page (first page) of the slide.pdf is available as slide-0.png | ||
fs.existsSync("/tmp/slide-0.png") // => true | ||
@@ -27,0 +31,0 @@ }); |
@@ -10,4 +10,8 @@ var assert = require("assert"); | ||
var pdfPath = "/tmp/test.pdf"; | ||
var pdfImage = new PDFImage(pdfPath); | ||
var pdfImage; | ||
beforeEach(function() { | ||
pdfImage = new PDFImage(pdfPath) | ||
}); | ||
it("should have correct basename", function () { | ||
@@ -32,3 +36,3 @@ expect(pdfImage.pdfFileBaseName).equal("test"); | ||
// TODO: Do page updating test | ||
it("should convert PDF's page to png file", function () { | ||
it("should convert PDF's page to a file with the default extension", function () { | ||
pdfImage.convertPage(1).then(function (imagePath) { | ||
@@ -44,2 +48,10 @@ expect(imagePath).equal("/tmp/test-1.png"); | ||
it("should convert PDF's page to file with a specified extension", function () { | ||
pdfImage.setConvertExtension("jpeg"); | ||
pdfImage.convertPage(1).then(function (imagePath) { | ||
expect(imagePath).equal("/tmp/test-1.jpeg"); | ||
expect(fs.existsSync("/tmp/test-1.jpeg")).to.be.true; | ||
}); | ||
}); | ||
it("should return # of pages", function () { | ||
@@ -57,4 +69,3 @@ pdfImage.numberOfPages().then(function (numberOfPages) { | ||
expect(pdfImage.constructConvertOptions()).equal("-density 300 -trim"); | ||
pdfImage.setConvertOptions(null); | ||
}); | ||
}); |
8196
196
53