Is there a way to count doc, docx, pdf pages with only js (without Node.js)?

自古美人都是妖i 提交于 2019-12-14 02:44:58

问题


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


来源:https://stackoverflow.com/questions/34762798/is-there-a-way-to-count-doc-docx-pdf-pages-with-only-js-without-node-js

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