Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 566
sparkle Avatar asked Apr 20 '12 21:04

sparkle


People also ask

How do I find out how many pages in a PDF?

The R package pdftools and the function pdf_info() provides information on the number of pages in a pdf.

How do I count the number of pages in a PDF in PHP?

It does not use any PHP library for performing this task. The following line of code can be used. $pageCount = (new TCPDI())->setSourceData((string)file_get_contents($fileName)); Method 3: Using pdfinfo: For Linux users, there is a faster way to count the number of pages in a pdf document than “identity” function.

How do I count the number of pages in a PDF using Python?

The 'PdfFileReader()' is an inbuilt function from the package 'PyPDF2'. 'numPages' will count the page numbers from the given PDF file. And the 'print()' function will display the result.


1 Answers

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);
})
like image 93
Sid Thakur Avatar answered Oct 04 '22 19:10

Sid Thakur