ImageMagick 7.0.4 / NodeJS 6.9.2 / GPLGS 9.15 / Win 7:无法转换文件

ImageMagick 7.0.4 / NodeJS 6.9.2 / GPLGS 9.15 / Win 7: Failing to convert files

问题

我可以使用 convert.exe ImageMagick 命令从命令行将 PDF 转换为另一种图像格式。但是,当 运行 在 Node 中执行以下 JS 时,我收到以下代码后的错误。

JavaScript

fs = require('fs');

var PDFImage = require("pdf-image").PDFImage;

console.log("Start");

var pdfImage = new PDFImage('test.pdf');
pdfImage.convertPage(0).then(function (imagePath) {
  // 0-th page (first page) of the slide.pdf is available as slide-0.png 
  console.log('Converted');
  fs.existsSync('test-0.png') // => true 
}, function (err) {
    console.log(err);
});

package.json

{
  "name": "pdftester",
  "version": "1.0.0",
  "description": "PDF Tester",
  "main": "PDFTester.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "John Doe",
  "license": "ISC",
  "dependencies": {
    "async": "^2.1.4",
    "imagemagick": "^0.1.3",
    "pdf-image": "^1.1.0",
    "pdftotextjs": "^0.4.0"
  }
}

结果

Start
{ message: 'Failed to convert page to image',
  error: 
   { Error: Command failed: convert 'test.pdf[0]' 'test-0.png'
   convert: unable to open image ''test.pdf[0]'': No such file or directory @ error/blob.c/OpenBlob/2691.
   convert: unable to open module file 'C:\ImageMagick-7.0.4-Q16\modules\coders\IM_MOD_RL_PDF[0]'_.dll': No such file or directory @ warning/module.c/GetMagickModulePath/680.
   convert: no decode delegate for this image format `PDF[0]'' @ error/constitute.c/ReadImage/509.
   convert: no images defined `'test-0.png'' @ error/convert.c/ConvertImageCommand/3254.

       at ChildProcess.exithandler (child_process.js:206:12)
       at emitTwo (events.js:106:13)
       at ChildProcess.emit (events.js:191:7)
       at maybeClose (internal/child_process.js:877:16)
       at Socket.<anonymous> (internal/child_process.js:334:11)
       at emitOne (events.js:96:13)
       at Socket.emit (events.js:188:7)
       at Pipe._handle.close [as _onclose] (net.js:498:12)
     killed: false,
     code: 1,
     signal: null,
     cmd: 'convert \'test.pdf[0]\' \'test-0.png\'' },
  stdout: '',
  stderr: 'convert: unable to open image \'\'test.pdf[0]\'\': No such file or directory @ error/blob.c/OpenBlob/2691.\r\nconvert: unable to open module file \'C:\ImageMagick-7.0.4-Q16\modules\coders\IM_MOD_RL_PDF[0]\'_.dll\': No such file or directory @ warning/module.c/GetMagickModulePath/680.\r\nconvert: no decode delegate for this image format `PDF[0]\'\' @ error/constitute.c/ReadImage/509.\r\nconvert: no images defined `\'test-0.png\'\' @ error/convert.c/ConvertImageCommand/3254.\r\n' }

分析

违规行是为convert.exe构建的命令行,即:

'convert \'test.pdf[0]\' \'test-0.png\''

什么是添加额外的斜杠、刻度线 (') 和“[0]”?

提前致谢!

根据你的问题,多余的斜杠表示进入文件夹。 你必须把你的文件从它开始的地方放在服务器文件中。或将您的 pdf 文件放入 运行 您的应用所在的位置。