如何修复 GraphicsMagik 错误(gm convert: No decode delegate for this image format)

How to fix the GraphicsMagik error (gm convert: No decode delegate for this image format)

所以我正在尝试制作一个小应用程序,它可以获取 PDF 文件并将它们转换为 node.js 中的图片。

我发现 pdf2pic 包非常适合我想做的事情。

因此,按照该软件包中的说明,我安装了 Ghostscript 和 Graphicsmagick,然后安装了该软件包。我在 Windows 顺便说一句。

这是我的 node.js 代码:

const { fromPath } = require("pdf2pic");

const options = {
  density: 100,
  saveFilename: "untitled",
  savePath: "./images",
  format: "png",
  width: 600,
  height: 600
};
const storeAsImage = fromPath("test.pdf", options);
const pageToConvertAsImage = 1;

storeAsImage(pageToConvertAsImage).then((resolve) => {
  console.log("Page 1 is now converted as image");

  return resolve;
}).catch(error => {
    console.log(error);
});

调整此代码后出现此错误:

Error: Command failed: gm convert: No decode delegate for this image format (C:\Users\Yosse_M\AppData\Local\Temp\gmRuQc4v).

    at ChildProcess.onExit (D:\Devs\NodeJS\app07-pdf2pic-test\node_modules\gm\lib\command.js:301:17)
    at ChildProcess.emit (events.js:315:20)
    at ChildProcess.cp.emit (D:\Devs\NodeJS\app07-pdf2pic-test\node_modules\cross-spawn\lib\enoent.js:40:29)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5) {
  code: 1,
  signal: null

这是命令 gm -version returns:

C:\Users\Yosse_M>gm -version
GraphicsMagick 1.3.36 20201226 Q16 http://www.GraphicsMagick.org/
Copyright (C) 2002-2020 GraphicsMagick Group.
Additional copyrights and licenses apply to this software.
See http://www.GraphicsMagick.org/www/Copyright.html for details.

Feature Support:
  Native Thread Safe         yes
  Large Files (> 32 bit)     yes
  Large Memory (> 32 bit)    yes
  BZIP                       yes
  DPS                        no
  FlashPix                   no
  FreeType                   yes
  Ghostscript (Library)      no
  JBIG                       yes
  JPEG-2000                  yes
  JPEG                       yes
  Little CMS                 yes
  Loadable Modules           yes
  Solaris mtmalloc           no
  Google perftools tcmalloc  no
  OpenMP                     yes (200203 "2.0")
  PNG                        yes
  TIFF                       yes
  TRIO                       no
  Solaris umem               no
  WebP                       yes
  WMF                        yes
  X11                        no
  XML                        yes
  ZLIB                       yes

Windows Build Parameters:

  MSVC Version:            1500

我不知道如何解决这个问题,请问有什么建议吗?

如果您需要更多信息,请告诉我。

谢谢

我也在为“GM 的 pdf 委托问题”而苦恼。我发现 GraphicsMagick 使用 Ghostscript 字体(也称为“URW 字体”)来支持标准的 Adob​​e Postscript 字体集,如“Helvetica”和“Times Roman”。 从这里下载字体 Ghostscript Fonts and paste downloaded folder fonts to the folder with Ghostscript files C:Program Files\gs\gs9.52. Here 您可以找到更多信息。

const { fromPath } = require("pdf2pic");

const options = {
  density: 100,
  saveFilename: "untitled",
  savePath: "./images",
  format: "png",
  width: 600,
  height: 600
};

try {
    const convert = fromPath("test.pdf", options);
    await convert.bulk(-1);
} catch (error) {
    console.log(error);

}