Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs pdf to image conversion

I am using https://www.npmjs.com/package/pdf-image.

 var PDFImage = require("pdf-image").PDFImage;

            var pdfImage = new PDFImage("brochure.pdf");
            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);
            });

But i am getting this error

 { message: 'Failed to convert page to image',
  error:
   { [Error: Command failed: /bin/sh -c convert 'brochure.pdf[0]' 'brochure-0.png'
   /bin/sh: 1: convert: not found
   ]
     killed: false,
     code: 127,
     signal: null,
     cmd: '/bin/sh -c convert \'brochure.pdf[0]\' \'brochure-0.png\'' },
  stdout: '',
  stderr: '/bin/sh: 1: convert: not found\n' }

Please help me how can i convert pdf to image using nodejs.

like image 468
Pritam Parua Avatar asked Nov 08 '22 12:11

Pritam Parua


1 Answers

You need to download ImageMagick in order to get the package working. You find see installation instructions on the documentation here

If you've already done so, there might be something gone wrong with your path configuration. Try these commands to fix that:

export MAGICK_HOME="opt/ImageMagick"
export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib
export PATH="$MAGICK_HOME/bin:$PATH"
like image 52
Karamell Avatar answered Nov 15 '22 06:11

Karamell