问题
我可以使用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\''是什么增加了额外的斜杠,蜱(')和''?
提前感谢!
发布于 2016-12-21 17:08:41
根据您的问题,额外的斜杠表示要输入文件夹。您必须将您的文件相对于服务器文件从它开始的位置放置。或者把你的pdf文件放在你运行应用程序的地方。
https://stackoverflow.com/questions/41267771
复制相似问题