yakovmeister / pdf2image

A utility for converting pdf to image and base64 format.
MIT License
435 stars 141 forks source link

GraphicsMagick/ImageMagick: gm couldn't be executed #204

Closed nikitimi closed 7 months ago

nikitimi commented 7 months ago

I'm using this API to get a pdf and this is a snippet of my current set-up:

    formData.append("file", fs.createReadStream("dirname/filepath"))
    const response = await axios.post(
      "https://api.pspdfkit.com/build",
      formData,
      {
        headers: formData.getHeaders({
          Authorization: "Bearer " + LIVE_API_KEY,
        }),
        responseType: "stream",
      }
    )

    await response.data.pipe(fs.createWriteStream(filename))
    const filepath = "dirname/filename"
    const options = {
      density: 100,
      saveFilename: "untitled",
      savePath: "./images",
      format: "png",
      width: 600,
      height: 600,
    }
    setTimeout(() => console.log("times up!"), 1000)
    const convert = fromPath(filepath, options)
    const pageToConvertAsImage = 1

    const result = await convert(pageToConvertAsImage, {
      responseType: "image",
    })
    console.log({ result })

I was getting the pdf from the API mentioned above but I'm getting this error with pdf2image:

/home/myusername/pptToImageApi/node_modules/gm/lib/command.js:249
        cb(new Error('Could not execute GraphicsMagick/ImageMagick: '+cmd+" this most likely means the gm/convert binaries can't be found"));
           ^

Error: Could not execute GraphicsMagick/ImageMagick: gm "convert" "-density" "100x100" "-quality" "75" "-[0]" "-resize" "600x600!" "-compress" "jpeg" "./images/untitled.1.png" this most likely means the gm/convert binaries can't be found
    at ChildProcess.<anonymous> (/home/realsyntexia/nikitimi/pptToImageApi/node_modules/gm/lib/command.js:249:12)
    at ChildProcess.emit (node:events:518:28)
    at ChildProcess._handle.onexit (node:internal/child_process:292:12)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
nikitimi commented 7 months ago

It turns out I just need to install GraphicsMagick in my machine

apt-get install graphicsmagick