如何修复GraphicsMagick错误(gm convert:此图像格式没有解码委托)

3

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

我发现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 的返回结果:

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

我不知道如何解决这个问题,能请你给出一些建议吗?
如果需要更多信息,请告诉我。
谢谢。

你好!你找到解决方案了吗?能帮我一下吗?我也遇到了同样的问题) - Anastassiya Grinvald
1
@AnastassiyaGrinvald 很抱歉回复晚了,不确定您是否已经解决了问题。无论如何,我停止使用Graphicsmagick和pdf2pic包,并使用Imagemagick。当您安装它时,您会得到一个名为“convert”的命令,可以将pdf转换为图片,因此我只需从我的节点应用程序中直接执行该命令,使用“exec()”。 - RustyJoe
1个回答

2
我也曾经遇到“GM的pdf委托问题”。后来我发现,GraphicsMagick使用Ghostscript字体(也称为“URW字体”)来支持标准的Adobe Postscript字体集,例如“Helvetica”和“Times Roman”。 从这里Ghostscript Fonts下载字体,并将下载的字体文件夹粘贴到带有Ghostscript文件的文件夹C:Program Files\gs\gs9.52中。这里可以找到更多信息。 enter image description 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);

}


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接