How to get the number of pages of a .PDF uploaded by user?

前端 未结 5 387
温柔的废话
温柔的废话 2020-12-06 11:14

I have a file input, and before \"uploading\" i need to calculate the number of pages of that .pdf in JAVASCRIPT (eg. JQuery...)

5条回答
  •  一个人的身影
    2020-12-06 11:31

    In case you use pdf.js you may reference an example on github ('.../examples/node/getinfo.js') with following code that prints number of pages in a pdf file.

    const pdfjsLib = require('pdfjs-dist');
    ...
    pdfjsLib.getDocument(pdfPath).then(function (doc) {
        var numPages = doc.numPages;
        console.log('# Document Loaded');
        console.log('Number of Pages: ' + numPages);
    }
    

提交回复
热议问题