node 怎么把pdf的封面给提取出来,求指教
发布于 8 年前 作者 martin823823 6035 次浏览 来自 问答

获取封面图片,谢谢。

8 回复

@elrrrrrrr @martin823823 我安装了imageMagic,但是运行的时候没报错也没图片生成,请问你们遇到过吗?

var PDFImage = require(“pdf-image”).PDFImage; var fs = require(“fs”);

var pdfImage = new PDFImage(“tmp/testpdf.pdf”); console.log(“Start”); 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(“tmp/testpdf-0.png”) // => true });

testpdf在个F:\parseWord\tmp里 untitled3.png

@SHocker-Yu var pdfImage = new PDFImage(“tmp/testpdf.pdf”); 传入的是文件的路径-》F:\parseWord\tmp\testpdf.pdf

@SHocker-Yu 你把imagePath打印出来看看

@martin823823 感谢回复,路径确认很多遍,绝对路径也正如你打出来的一样试过了,imagePath打不出来,程序没有运行到里面就结束了。 最后是换了gm这个包,感觉很强大,https://github.com/aheckmann/gm

gm(‘tmp/testpdf.pdf[0]’) .resize(800, 800) .noProfile() .write(‘tmp/test1.png’, function(err) { if (!err) console.log(‘done’); });

@SHocker-Yu 按照你的办法,我这边提示。

{ [Error: Command failed: convert: no images defined `/Users/zhailei/Documents/github/testApps/aaaaaaa.png’ @ error/convert.c/ConvertImageCommand/3257. ] code: 1, signal: null }

@zhailei31665431 周末没上社区,不好意思,这是因为没有安装ghostscript,下载地址:http://ghostscript.com/download/gsdnld.html

回到顶部