I need to count number of pages in doc, docx and pdf files.
I know that it is possible to do with PHP, NodeJS
But is it possible to do it with only javascript if file is on server?
I need to count number of pages in doc, docx and pdf files.
I know that it is possible to do with PHP, NodeJS
But is it possible to do it with only javascript if file is on server?
https://www.npmjs.com/package/docx-pdf-pagecount can be used to get docx and pdf page count.
const getPageCount = require('docx-pdf-pagecount');
getPageCount('E:/sample/document/aa/test.docx')
.then(pages => {
console.log(pages);
})
.catch((err) => {
console.log(err);
});
getPageCount('E:/sample/document/vb.pdf')
.then(pages => {
console.log(pages);
})
.catch((err) => {
console.log(err);
});
First you need to download zip file from here
after that
PDFPageCount.getPageCount(target PDF file,callback function);
EXAMPLE
**PDFPageCount.getPageCount("HTML5_draft.pdf", callbackFunc); **
Once the page count is detected the callback function will get the page count as a return parameter
**To find out page number of PDF files**
<script src="js/pdf.js?1444224269"></script>
PDFJS.workerSrc = "js/pdf.worker.js";
var fileLocation = 'test.pdf';
var numPages = 0;
PDFJS.getDocument(fileLocation).then(function(pdf) {
numPages = pdf.numPages;
});