javascriptnode.jsimagemagickgm

gm/convert binaries can't be found Node.js pdf-to-image conversion


I am using https://www.npmjs.com/package/pdf2pic to convert my PDF to image.

const PDF2Pic = require('pdf2pic');

const pdf2pic = new PDF2Pic({
  density: 100, // output pixels per inch
  savename: 'untitled', // output file name
  savedir: './images', // output file location
  format: 'png', // output file format
  size: '600x600', // output size in pixels
});

const file = "/Users/kar1/Downloads/bw.pdf"
async function recognizeFile(file) {
  pdf2pic.convertBulk(file, -1).then((resolve) => {
    console.log('image converter successfully!');

    return resolve;
  });
}

recognizeFile(file)

The error :

(node:32605) UnhandledPromiseRejectionWarning: Error: Could not execute GraphicsMagick/ImageMagick: gm "identify" "-ping" "-format" "%p" "/Users/kar1/Downloads/bw.pdf" this most likely means the gm/convert binaries can't be found
    at ChildProcess.<anonymous> (/Users/kar1/Desktop/github/pdfToPic/node_modules/gm/lib/command.js:232:12)
    at ChildProcess.emit (events.js:315:20)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

I tried :

brew install imagemagick

And the issue still persists. How can I solve this?


Solution

  • Problem got solved by running these commands :

    brew install imagemagick
    brew install gs