我正在使用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' }请告诉我如何使用nodejs将pdf转换为图片。
发布于 2016-06-30 00:12:38
您需要下载ImageMagick才能使包正常工作。您可以在documentation here上找到安装说明
如果你已经这样做了,可能是你的路径配置出了问题。尝试使用以下命令来解决此问题:
export MAGICK_HOME="opt/ImageMagick"
export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib
export PATH="$MAGICK_HOME/bin:$PATH"发布于 2018-05-03 17:15:00
你必须更改软件包有一个npm软件包,可以将PDF文件转换为图像文件: pdf-poppler它工作得很好,试试https://www.npmjs.com/package/pdf-poppler吧,祝你好运。
https://stackoverflow.com/questions/38104932
复制相似问题