Node.js PDF转换成图片

5
我正在使用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);
            });

但我遇到了这个错误。
 { 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' }

请帮我,如何使用Node.js将PDF转换为图像。

3个回答

2

为了使该软件包正常工作,您需要下载ImageMagick。您可以在文档这里找到安装说明。

如果您已经完成了上述步骤,但仍然无法使用该软件包,则可能是路径配置出现了问题。请尝试使用以下命令进行修复:

export MAGICK_HOME="opt/ImageMagick"
export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib
export PATH="$MAGICK_HOME/bin:$PATH"

我已经成功运行了这个命令。sudo apt-get install imagemagick ghostscript poppler-utils - Pritam Parua
如果你运行 which convert,会得到什么结果? - Karamell
如果您需要设置路径,可以通过在终端中输入以下命令来完成(假设您使用的是Mac或Unix系统):export MAGICK_HOME="opt/ImageMagick" && export PATH="$MAGICK_HOME/bin:$PATH" && export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib" - Karamell
尝试以下内容:这里 - Karamell

0

显示此类型的错误 尝试新的跨平台 PowerShell https://aka.ms/pscore6

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

添加了1个软件包,并在6秒内审核了334个软件包

19个软件包正在寻求资助 运行npm fund以获取详细信息

8个漏洞(5个高危,3个严重)

要解决不需要注意的问题,请运行: npm audit fix

要解决所有可能的问题(包括破坏性更改),请运行: npm audit fix --force

某些问题需要审查,并可能需要选择 不同的依赖项。

运行npm audit以获取详细信息。 PS C:\Users\mepan\Downloads\bg remove>


1
你的回答可以通过提供额外的支持信息来改进。请通过[编辑]添加更多细节,例如引文或文档,以便他人可以确认您的答案是否正确。您可以在帮助中心找到有关撰写良好答案的更多信息。 - Community

-1

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