Find PDF page count with Node (on Windows)

假如想象 提交于 2019-12-10 13:39:43

问题


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!!


回答1:


Since 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');


来源:https://stackoverflow.com/questions/30131280/find-pdf-page-count-with-node-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!