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

前端 未结 5 388
温柔的废话
温柔的废话 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:26

    As has been stated in the other answers, something like pdf.js is be what you are looking for. I've taken a look at the API and it does include a numPages() function to return the total number of pages. It also seems to count pages for me when viewing the demo page from Mozilla.

    It depends if you are able to use modern browsers and experimental technology for your solution. pdf.js is very impressive, but it is still experimental according to the github page .

    If you are able to count the pages on the server after uploading, then you should look at pdftools or similar.

    Something like pdftools --countpages is what you are looking for

提交回复
热议问题