Pri*_*rua 5 pdf imagemagick node.js imagemagick-convert
我正在使用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);
});
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误
{ 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' }
Run Code Online (Sandbox Code Playgroud)
请帮助我如何使用nodejs将pdf转换为图像。
您需要下载 ImageMagick 才能使该包正常工作。您可以在此处找到文档中的安装说明
如果您已经这样做了,则您的路径配置可能有问题。尝试这些命令来解决这个问题:
export MAGICK_HOME="opt/ImageMagick"
export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib
export PATH="$MAGICK_HOME/bin:$PATH"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18448 次 |
| 最近记录: |