Open matt212 opened 8 years ago
Same for me on OS X 10.11.
Oh, it was a path issue.
This works for me with a pdf in tmp/testpdf.pdf
:
var PDFImage = require("pdf-image").PDFImage;
var fs = require("fs");
var pdfImage = new PDFImage("tmp/testpdf.pdf");
console.log("Start");
pdfImage.convertPage(0).then(function (imagePath) {
// 0-th page (first page) of the slide.pdf is available as slide-0.png
console.log("Converted.");
fs.existsSync("tmp/testpdf-0.png") // => true
});
@timpulver Hi,i used your code,but there is no errors,and no 'Converted.' I have already installed imageMagic,my testpdf.pdf file's path is in :F:\parseWord\tmp. Could you help me?
I console the err:
pdfImage.convertPage(0).then(function(imagePath) {
// 0-th page (first page) of the slide.pdf is available as slide-0.png
fs.existsSync("slide-0.png") // => true
}, function(err) {
console.log(err);
});
F:\parseWord>node pdf-img.js
{ message: 'Failed to convert page to image',
error:
{ [Error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c "convert 'brochure.pdf[0]' 'brochure-0.png'"
������ - 'brochure-0.png'
]
killed: false,
code: 4,
signal: null,
cmd: 'C:\\WINDOWS\\system32\\cmd.exe /s /c "convert \'brochure.pdf[0]\' \'brochure-0.png\'"' },
stdout: '',
stderr: '������ - \'brochure-0.png\'\r\n' }
@SHocker-Yu
Try this one:
var PDFImage = require("pdf-image").PDFImage;
var fs = require("fs");
var pdfImage = new PDFImage("tmp/test.pdf");
console.log("Start");
pdfImage.convertPage(0).then(function (imagePath) {
// 0-th page (first page) of the slide.pdf is available as slide-0.png
console.log("Converted.");
fs.existsSync("tmp/testpdf-0.png") // => true
}, function (err) {
console.log(err);
});
process.on('uncaughtException', function (err) {
console.log('Caught exception: ' + err);
});
If the error message does not lead to something, it could be a path problem.
My directory structure looks like this:
somedir/index.js
somedir/tmp/test.pdf
I do cd somedir
and then node index.js
.
Hope this helps.
@timpulver Thanks for your reply!It's so kind of you. I tried your code and there is nothing console with
process.on('uncaughtException', function (err) {
console.log('Caught exception: ' + err);
});
And,i checked my directory structure,they like this:
F:/parseWord/tmp/testpdf.pdf
F:/parseWord/pdf-image.js
I think it's no the problem. I want to make sure that can you use this package successfully.
@timpulver Oh,i just using gm module https://github.com/aheckmann/gm, and it works successfully.
This part should make noise if the file e.g. cannot be found:
}, function (err) {
console.log(err);
});
@timpulver I'm so sorry that there is no error now,it's the same code,I think it's about the software "GraphicsMagick",this is the only difference,I have installed it last-night for the package "gm",before this,i just installed "ImageMagick" and "Ghostscript", and now it can
console.log('Converted.')
,but it no generates anything.
@timpulver I do a test just now,it's so strange! and it's none of the business with GraphicsMagick . if the file "tmp/testpdf-0.png" exists(I use the command line to achieve with ImageMagick) ,it will console.log("Converted."),if not,it just console.log("Start") and no error console with code:
var PDFImage = require("pdf-image").PDFImage;
var fs = require("fs");
var pdfImage = new PDFImage("tmp/testpdf.pdf");
console.log("Start");
pdfImage.convertPage(0).then(function (imagePath) {
// 0-th page (first page) of the slide.pdf is available as slide-0.png
console.log("Converted.");
fs.existsSync("tmp/testpdf-0.png") // => true
});
process.on('uncaughtException', function (err) {
console.log('Caught exception: ' + err);
});
Anyway,I want you to know how much i appreciate your help. Best.
my operating system us win 7 and when running provided codebase i am not able to see generated images not even errors
my codebase var PDFImage = require("pdf-image").PDFImage;
var pdfImage = new PDFImage("./tmp/a.pdf");
console.log(pdfImage); pdfImage.convertPage(0).then(function (imagePath) { // 0-th page (first page) of the slide.pdf is available as slide-0.png fs.existsSync("/tmp/slide-0.png") // => true });
process.on('uncaughtException', function (err) { console.log('Caught exception: ' + err); });