【问题标题】:nodejs pdf to image conversionnodejs pdf到图片的转换
【发布时间】:2016-11-01 11:26:01
【问题描述】:

我正在使用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 转换为图像。

【问题讨论】:

    标签: node.js pdf imagemagick imagemagick-convert


    【解决方案1】:

    您需要下载 ImageMagick 才能使软件包正常工作。您可以在文档here

    上找到安装说明

    如果您已经这样做了,那么您的路径配置可能有问题。试试这些命令来解决这个问题:

    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 @Karamell
    • 运行which convert会有什么结果?
    • 如果你需要设置路径,你可以通过在终端(假设是mac或unix)中输入:export MAGICK_HOME="opt/ImageMagick" && export PATH="$MAGICK_HOME/bin:$PATH" && export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib"
    • 试试this
    【解决方案2】:

    你必须更改包有一个 npm 包可以将 PDF 文件转换为图像文件:pdf-poppler 它工作正常试试看 https://www.npmjs.com/package/pdf-poppler 祝你好运

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-21
      • 2011-11-28
      • 1970-01-01
      • 2016-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-13
      相关资源
      最近更新 更多