eivindfjeldstad / imagemagick-stream

Streaming Imagemagick API
MIT License
92 stars 22 forks source link

Support for converting pdf to png #21

Open ankitrshah89 opened 8 years ago

ankitrshah89 commented 8 years ago

Hi @eivindfjeldstad ,

Does imagemagick-stream support converting PDFs to images?

I wrote a test for the same :

const im = require('imagemagick-stream'); const fs = require('fs');

const read = fs.createReadStream(dirname + '/pdfs/samplePdf.pdf'); const write = fs.createWriteStream(dirname + '/pdfs/image-resized.png');

const resize = im(); read.pipe(resize).pipe(write);

Unfortunately I got this error: events.js:141 throw er; // Unhandled 'error' event ^

Error: convert: no decode delegate for this image format ' @ error/constitute.c/ReadImage/508. convert: no images defined-' @ error/convert.c/ConvertImageCommand/3235.

at ImageMagick.onerror (/srv/package/node_modules/imagemagick-stream/index.js:273:31)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at Socket.Readable.push (_stream_readable.js:110:10)
at Pipe.onread (net.js:523:20)

I tried to use convert which got installed as part of imagemagick through cli and I could successfully convert it.

Any ideas?

Thanks!

tero commented 6 years ago

@ankitrshah89 Did you resolve this? Got same issue when trying to convert svg to jpeg.

WaldoJeffers commented 6 years ago

@ankitrshah89 I think you need to install ghostscript brew install ghostscript

I had the same issue & this solved it for me

AlexanderButyaev commented 6 years ago

What about multipage PDFs? how to pipe it in different files?