Open kcollignon opened 9 years ago
Hi!
Try something like this:
var pdfImage = new pdf("file.pdf");
pdfImage.getInfo().then(function (info) {
for(var i = 1; i <= info["Pages"]; i++){
pdfImage.convertPage(i).then(function (imagePath) {
fs.existsSync(i + ".png");
});
}
});
I, too, would like this cooked in, but would adding this functionality using the existing convertPage
get too heavy with a Promise for each page?
Would like a convertAllPages
method too!
I too would like a convertAllPages
method!
I too would like a convertAllPages method!
+1
Please update to Version 2.0.0 to use this Feature:
var PDFImage = require("pdf-image").PDFImage;
var pdfImage = new PDFImage("/tmp/slide.pdf");
pdfImage.convertFile().then(function (imagePaths) {
// [ /tmp/slide-0.png, /tmp/slide-1.png ]
});
Can anyone confirm this works? I can do my own gm convert
commands in my container, but when I try to use this library, the call to convertFile() doesn't exit and I'm not seeing any extra CPU/memory activity for more than 1-2 seconds.
Maybe I'm still doing something wrong?
gm convert -verbose -density 150 ./test.pdf -quality 100 -type TrueColorMatte +adjoin test1/test1-%04d.png
lab.test('convert PDF to images', { timeout: 10000000 }, () => {
return new Promise( (resolve, reject) => {
const PDFImage = require('pdf-image').PDFImage;
console.log('about to convert');
let pdfImage = new PDFImage( pdfPath,
{
graphicsMagick: true,
convertOptions: {
'-density': '150',
'-quality': '100',
'-depth': '8',
'-background': 'white',
'-flatten': null
}
}
).convertFile()
.then( imagePaths => {
console.log('done converting'); // <--- THIS IS NEVER HIT
console.dir( imagePaths )
expect( imagePaths ).to.be.a.array();
resolve();
})
.catch( err => {
console.error( { errorConverting: err } );
expect( err ).to.be.a.null();
});
console.log(' OUT! '); // This is logged immediately
});
});
I see that you have to pass the page number that you would like as an image, but it would be helpful if there is an option to split every page of a PDF to an image, rather than having to know the exact page number.