'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.



Solution 1:[1]

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"

Solution 2:[2]

showing this type of error Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\Users\mepan\Downloads\bg remove> npm install pdf-image

added 1 package, and audited 334 packages in 6s

19 packages are looking for funding run npm fund for details

8 vulnerabilities (5 high, 3 critical)

To address issues that do not require attention, run: npm audit fix

To address all issues possible (including breaking changes), run: npm audit fix --force

Some issues need review, and may require choosing a different dependency.

Run npm audit for details. PS C:\Users\mepan\Downloads\bg remove>

Solution 3:[3]

you have to change the package there is an npm package that converts PDF file to image file : pdf-poppler it works fine try it https://www.npmjs.com/package/pdf-poppler Best of luck

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Soviut
Solution 2 Mehul Panchal
Solution 3 Asma_Kh