问题
我可以使用convert.exe
ImageMagick命令从命令行执行从PDF到另一种图像格式的转换。但是,在Node I中运行以下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\''
什么是添加额外的斜杠,刻度线(&#39;)和&#39; [0]&#39;?
提前致谢!
答案 0 :(得分:0)
根据您的问题,额外的斜杠表示进入文件夹。 你必须把你的文件放在它开始的位置的服务器文件中。或者将您的pdf文件放入运行应用程序的位置。