Is there a way to count doc, docx, pdf pages with

2019-08-05 13:48发布

问题:

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?

回答1:

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);
  });


回答2:

First you need to download zip file from here

after that

  • Include the PDFPageCount.js library into your target page
  • Call the function in the format

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



回答3:

**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;
});