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

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

    and a pure javascript solution:

    var input = document.getElementById("files");
    var reader = new FileReader();
    reader.readAsBinaryString(input.files[0]);
    reader.onloadend = function(){
        var count = reader.result.match(/\/Type[\s]*\/Page[^s]/g).length;
        console.log('Number of Pages:',count );
    }
    

提交回复
热议问题