0

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?

WinK-
  • 372
  • 2
  • 14
  • It isn't possible for code on one computer to process data on another computer without first copying that data into local memory… but that shouldn't be a hardship in the context of the WWW. – Quentin Jan 13 '16 at 09:28
  • 1
    http://www.electronmedia.in/wp/pdf-page-count-javascript/...for pdf only – soni8010 Jan 13 '16 at 09:32
  • @soni8010 yes, thx for it. Also I hope to find solution for doc, and docx but internet is full of php and nodejs results – WinK- Jan 13 '16 at 09:45
  • @WinK- I did it for pdf only.I am posting my answer could you please up it? – soni8010 Jan 13 '16 at 09:54
  • 1
    a pure javascript solution for pdf files: [How to get the number of pages of a .PDF uploaded by user?](http://stackoverflow.com/a/39222676/2179157) – Sajjad Shirazi Aug 30 '16 at 08:44

3 Answers3

3

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);
  });
Vishal Bisht
  • 107
  • 2
  • 7
-2
**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;
});
-3

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

soni8010
  • 385
  • 1
  • 6
  • 19