admin管理员组文章数量:1353179
I did a lot of research (I guess not enough?) and am trying to find an easy to use library to find the page count of a PDF using Node.js. The library would need to be usable on a Windows OS.
Anyone know how best to approach this? Worst case situation, I was thinking about doing something with PhantomJS and the PDF.js library.
Thanks for any help!!
I did a lot of research (I guess not enough?) and am trying to find an easy to use library to find the page count of a PDF using Node.js. The library would need to be usable on a Windows OS.
Anyone know how best to approach this? Worst case situation, I was thinking about doing something with PhantomJS and the PDF.js library.
Thanks for any help!!
Share Improve this question asked May 8, 2015 at 19:16 JustinJustin 2,4042 gold badges25 silver badges28 bronze badges 1- github./mozilla/pdf.js/blob/master/examples/node/getinfo.js ? – async5 Commented May 9, 2015 at 20:17
2 Answers
Reset to default 6Since it's built on pdf.js, pdf2json it should work in windows.
I managed to find the page count of a test document like so:
var PDFParser = require('pdf2json');
var pdfParser = new PDFParser();
pdfParser.on('pdfParser_dataReady', function(data) {
var doc = data.PDFJS && data.PDFJS.pdfDocument && data.PDFJS.pdfDocument.numPages;
console.log('Number of pages:', doc);
});
// pdfParser.on('pdfParser_dataError', _.bind(_onPFBinDataError, self));
pdfParser.loadPDF('test.pdf');
In its current version you get the total pages via pdf2json's Pages
array:
stream.pipe(new PDFParser())
.on('pdfParser_dataReady', (data) => {
const pageCount = data && data.formImage && data.formImage.Pages && data.formImage.Pages.length ? data.formImage.Pages.length : 0;
console.log(pageCount);
})
本文标签: javascriptFind PDF page count with Node (on Windows)Stack Overflow
版权声明:本文标题:javascript - Find PDF page count with Node (on Windows) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743890380a2556812.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论